|
//using FluentAssertions;
//using FluentAssertions.Mvc;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
//using Moq;
//using System;
//using System.Collections.Generic;
//using System.Data.Common;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
//using System.Web.Mvc;
//using YouConf.Controllers;
//using YouConf.Data;
//using YouConf.Data.Entities;
//namespace YouConf.Tests.Controllers
//{
// [TestClass]
// public class ConferenceControllerTests
// {
// private YouConfDbContext _context;
// /// <summary>
// /// Thanks to for the idea to use Effort
// /// http://www.codeproject.com/Articles/460175/Two-strategies-for-testing-Entity-Framework-Effort
// /// </summary>
// [TestInitialize]
// public void SetupTest()
// {
// // create a new DbConnection using Effort
// DbConnection connection = Effort.DbConnectionFactory.CreateTransient();
// // use the same DbConnection object to create the context object the test will use.
// _context = new YouConfDbContext(connection);
// //_context.Configuration.ValidateOnSaveEnabled = false;
// }
// [TestCleanup]
// public void Cleanup()
// {
// _context.Dispose();
// }
// [TestMethod]
// public void All_Should_ReturnOnlyPublicConferences()
// {
// //Setup a stub repository to return three public conferences and one private
// _context.Conferences.Add(new Conference(){ AvailableToPublic = true});
// _context.Conferences.Add(new Conference(){ AvailableToPublic = true});
// _context.Conferences.Add(new Conference(){ AvailableToPublic = true});
// _context.Conferences.Add(new Conference(){ AvailableToPublic = false});
// _context.SaveChanges();
// var conferenceController = new ConferenceController(_context);
// var result = conferenceController.All()
// .As<ViewResult>();
// result.Model
// .As<IEnumerable<Conference>>()
// .Should().HaveCount(3);
// }
// [TestMethod]
// public void Details_WithInvalidHashTag_Should_ReturnHttpNotFoundResult()
// {
// var conferenceController = new ConferenceController(_context);
// var result = conferenceController.Details("thisisinvalid")
// .As<HttpNotFoundResult>();
// }
// [TestMethod]
// public void Details_WithValidHashTag_Should_ReturnCorrectConference()
// {
// var stubRepository = new Mock<IYouConfDataContext>();
// var stubConference = new Conference() { HashTag = "abcde" };
// stubRepository
// .Setup(x => x.GetConference("abcde"))
// .Returns(stubConference);
// var conferenceController = new ConferenceController(_context);
// var result = conferenceController.Details("abcde")
// .As<ViewResult>();
// result.Model
// .As<Conference>()
// .Should()
// .Be(stubConference);
// }
// [TestMethod]
// public void Create_WithAlreadyUsedHashTag_Should_ReturnViewAndAddModelError()
// {
// var stubRepository = new Mock<IYouConfDataContext>();
// var stubConference = new Conference() { HashTag = "abcde" };
// stubRepository
// .Setup(x => x.GetConference("abcde"))
// .Returns(stubConference);
// var conferenceController = new ConferenceController(_context);
// var newConference = new Conference() { HashTag = "abcde" };
// var result = conferenceController.Create(newConference)
// .As<ViewResult>();
// result.ViewData.ModelState["HashTag"]
// .Errors
// .Count
// .Should()
// .Be(1);
// }
// }
//}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm a software developer based in the beautiful city of Wellington, New Zealand. I love experimenting with new .Net technologies as they arrive, and these days there seems to be a lot of choice as there are so many new features in the framework! My current interests are Azure, ASP.Net MVC, SignalR, Knockout, AngularJS, and responsive design (inc. using Bootstrap, Foundation, Skeleton). These change fairly often as I tinker with various new technologies...