public void RenderDefaultView_WithExpectedViewModel() { // Arrange var domainService = new Mock <IDomainService>(); var userService = new Mock <IUserService>(); var loggedInUser = new Mock <ILoggedInUser>(); var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object); string name = "name"; Guid guid = Guid.NewGuid(); var domain = new Domain() { Id = 1, Name = "name", VerificationCode = guid }; domainService.Setup(d => d.GetDomainByName(name + ".com")).Returns(domain); // Act & Assert sellerController .WithCallTo(s => s.Validate(name)) .ShouldRenderDefaultPartialView() .WithModel <ValidateDomainViewModel>( v => { Assert.AreEqual(1, v.Id); Assert.AreEqual("name", v.Name); Assert.AreEqual(guid.ToString().ToUpper(), v.VerificationCode); }); }
public void RenderDefaultView_WithExpectedViewModel() { // Arrange var domainService = new Mock <IDomainService>(); var userService = new Mock <IUserService>(); var loggedInUser = new Mock <ILoggedInUser>(); var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object); var userId = "userId"; loggedInUser.Setup(l => l.GetUserId()).Returns(userId); var domains = new List <Domain>() { new Domain() { Name = "name" } }; domainService.Setup(d => d.GetSellerPendingDomainsByUserId(userId)).Returns(domains.AsQueryable <Domain>()); // Act & Assert sellerController .WithCallTo(s => s.Pending()) .ShouldRenderPartialView("_Pending") .WithModel <IEnumerable <PartialDomainViewModel> >( p => { Assert.AreEqual(1, p.Count()); Assert.AreEqual("name", p.First().Name); Assert.AreEqual("Pending", p.First().Status); }); }
public void Return_SameView_When_ModelState_is_Invalid() { // Arrange var domainService = new Mock <IDomainService>(); var userService = new Mock <IUserService>(); var loggedInUser = new Mock <ILoggedInUser>(); var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object); sellerController.ModelState.AddModelError("", "dummy error"); var userId = "userId"; loggedInUser.Setup(l => l.GetUserId()).Returns(userId); AddDomainViewModel addDomainViewModel = new AddDomainViewModel() { Name = "name", Description = "description" }; // Act & Assert sellerController .WithCallTo(s => s.AddDomain(addDomainViewModel)) .ShouldRenderDefaultView() .WithModel <AddDomainViewModel>(); }
public void RenderPartialView_AddDomain() { // Arrange var domainService = new Mock <IDomainService>(); var userService = new Mock <IUserService>(); var loggedInUser = new Mock <ILoggedInUser>(); var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object); // Act & Assert sellerController.WithCallTo(c => c.AddDomain()).ShouldRenderPartialView("_AddDomain"); }
public void RedirectToAction_When_Param_IsNull() { // Arrange var domainService = new Mock <IDomainService>(); var userService = new Mock <IUserService>(); var loggedInUser = new Mock <ILoggedInUser>(); var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object); string name = null; // Act & Assert sellerController .WithCallTo(s => s.Validate(name)) .ShouldRedirectTo(s => s.Index()); }
public void RedirectToAction_When_ReturnedDomain_IsNull() { // Arrange var domainService = new Mock <IDomainService>(); var userService = new Mock <IUserService>(); var loggedInUser = new Mock <ILoggedInUser>(); var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object); Domain domain = null; string name = "name"; domainService.Setup(d => d.GetDomainByName(name)).Returns(domain); // Act & Assert sellerController .WithCallTo(s => s.Validate(name)) .ShouldRedirectTo(s => s.Index()); }
public void RenderDefaultView_WithExpectedViewModel() { // Arrange var domainService = new Mock <IDomainService>(); var userService = new Mock <IUserService>(); var loggedInUser = new Mock <ILoggedInUser>(); var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object); string name = "name"; Guid guid = Guid.NewGuid(); var domain = new Domain() { Id = 1, Name = "name", Description = "description", Price = 1, OriginalOwnerCustomPrice = 1 }; domainService.Setup(d => d.GetDomainByName(name + ".com")).Returns(domain); // Act & Assert sellerController .WithCallTo(s => s.Edit(name)) .ShouldRenderDefaultPartialView() .WithModel <EditDomainViewModel>( e => { Assert.AreEqual(1, e.Id); Assert.AreEqual("name", e.Name); Assert.AreEqual("description", e.Description); Assert.AreEqual(1, e.Price); Assert.AreEqual(1, e.OwnerCustomPrice); }); }
public void RenderDefaultView_WithExpectedViewModel() { // Arrange var domainService = new Mock <IDomainService>(); var userService = new Mock <IUserService>(); var loggedInUser = new Mock <ILoggedInUser>(); var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object); string userId = "userId"; var createdOn = new DateTime(17, 1, 1); var user = new User() { Id = userId, FirstName = "firstname", LastName = "lastname" }; var rejectedDomains = new List <Domain>() { new Domain() { StatusId = 2 } }; var pendingDomains = new List <Domain>() { new Domain() { StatusId = 1 } }; var publishedDomains = new List <Domain>() { new Domain() { StatusId = 4 } }; var soldDomains = new List <Domain>() { new Domain() { StatusId = 5 } }; user.SellerDomains.Add(rejectedDomains[0]); user.SellerDomains.Add(pendingDomains[0]); user.SellerDomains.Add(publishedDomains[0]); user.SellerDomains.Add(soldDomains[0]); user.CreatedOn = createdOn; user.Balance = 10000; loggedInUser.Setup(l => l.GetUserId()).Returns(userId); userService.Setup(u => u.GetUserByStringId(userId)).Returns(user); // Act & Assert sellerController .WithCallTo(s => s.Index()) .ShouldRenderDefaultView() .WithModel <SellerProfileBoxStatsViewModel>( s => { Assert.AreEqual(user.FirstName + " " + user.LastName, s.FullName); Assert.AreEqual(user.FirstName[0].ToString() + user.LastName[0].ToString(), s.Initials); Assert.AreEqual(createdOn, s.MemberSince); Assert.AreEqual(Math.Round(user.Balance / 1000, 0) + "k", s.BalanceInKUsd); Assert.AreEqual(10000, s.Balance); Assert.AreEqual(4, s.SubmittedDomains); Assert.AreEqual(1, s.RejectedDomains); Assert.AreEqual(1, s.PendingDomains); Assert.AreEqual(1, s.PublishedDomains); Assert.AreEqual(1, s.SoldDomains); }); }