public async void Wishlist_GameWithNoProducts_IsNotInModel() { var game = new Game { Id = new Guid("09BD7D30-5268-4A02-A400-1F302040B6AA"), GameSKUs = new List<GameProduct>() }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { game }.AsQueryable()); dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object); Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Platform>().AsQueryable()); dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object); Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member>().AsQueryable()); dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.Wishlist() as ViewResult; Assert.That(result != null); var model = (WishlistViewModel)result.Model; Assert.That(model.Games.Count(), Is.EqualTo(0)); Assert.That(model.WishlistCount, Is.EqualTo(0)); }
public void MemberDetail_UsernameIsNullOrWhitespace_Throws404Exception([Values(null, "", " ")]string userName) { var controller = new ReportsController(null); Assert.That(async () => await controller.MemberDetail(userName), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(ex => ex.GetHttpCode() == 404)); }
public void MemberDetail_UserNotFound_Throws404Exception() { var member = new Member { UserAccount = new User { UserName = "******", FirstName = "Test", LastName = "User" }, FavoriteTags = new List<Tag>(), FavoritePlatforms = new List<Platform>(), Wishlist = new List<Product>(), ReceivedFriendships = new List<Friendship>(), RequestedFriendships = new List<Friendship>(), WebOrders = new List<WebOrder>() }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { member }.AsQueryable()); dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object); ReportsController controller = new ReportsController(dbStub.Object); Assert.That(async () => await controller.MemberDetail("NotTestUser"), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(ex => ex.GetHttpCode() == 404)); }
public async void GameListWithOrders_ContainsOrders_CorrectQuantity() { Guid productId = new Guid("9AEE5E2E-378D-4828-B142-F69B81C53D8C"); GameProduct gameProduct = new PhysicalGameProduct { Id = productId }; Game game = new Game { GameSKUs = new List<GameProduct> { gameProduct } }; WebOrder webOrder = new WebOrder { OrderItems = new List<OrderItem> { new OrderItem { Product = gameProduct, ProductId = gameProduct.Id, Quantity = 2 } } }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Game>> dbGameStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> {game}.AsQueryable()); dbStub.Setup(db => db.Games).Returns(dbGameStub.Object); Mock<DbSet<WebOrder>> dbWebOrdersStub = TestHelpers.GetFakeAsyncDbSet(new List<WebOrder> {webOrder}.AsQueryable()); dbStub.Setup(db => db.WebOrders).Returns(dbWebOrdersStub.Object); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.GameList() as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<DateFilteredListViewModel<GameListRowViewModel>>()); var model = (DateFilteredListViewModel<GameListRowViewModel>)result.Model; var items = model.Items; Assert.That(items.Count, Is.EqualTo(1)); var item = items[0]; Assert.That(item.QuantitySold, Is.EqualTo(2)); }
public async void MemberWithNoOrders_SetsOrderCountTo0() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); SetupVeilDataAccessWithUser(dbStub, memberUser); SetupVeilDataAccessWithWebOrders(dbStub, new List<WebOrder>()); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.MemberList() as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<DateFilteredListViewModel<MemberListItemViewModel>>()); var model = (DateFilteredListViewModel<MemberListItemViewModel>)result.Model; var items = model.Items; Assert.That(items.First().OrderCount, Is.EqualTo(0)); }
public async void GameDetailWithOrders_NoOrders() { Guid gameId = new Guid("40D655DF-FB62-4FD5-8065-A81C9868B145"); Guid productId = new Guid("9AEE5E2E-378D-4828-B142-F69B81C53D8C"); GameProduct gameProduct = new PhysicalGameProduct { Id = productId, GameId = gameId }; Game game = new Game { GameSKUs = new List<GameProduct>() }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Game>> dbGameStub = TestHelpers.GetFakeAsyncDbSet(new List<Game>().AsQueryable()); dbStub.Setup(db => db.Games).Returns(dbGameStub.Object); Mock<DbSet<GameProduct>> dbGameProductStub = TestHelpers.GetFakeAsyncDbSet(new List<GameProduct> { gameProduct }.AsQueryable()); dbStub.Setup(db => db.GameProducts).Returns(dbGameProductStub.Object); Mock<DbSet<WebOrder>> dbWebOrdersStub = TestHelpers.GetFakeAsyncDbSet(new List<WebOrder>().AsQueryable()); dbStub.Setup(db => db.WebOrders).Returns(dbWebOrdersStub.Object); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.GameDetail(gameId) as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<GameDetailViewModel>()); var model = (GameDetailViewModel)result.Model; Assert.That(model.Items.Count, Is.EqualTo(1)); Assert.That(model.TotalNewSales, Is.EqualTo(0)); Assert.That(model.TotalUsedSales, Is.EqualTo(0)); Assert.That(model.TotalSales, Is.EqualTo(0)); Assert.That(model.TotalNewQuantity, Is.EqualTo(0)); Assert.That(model.TotalUsedQuantity, Is.EqualTo(0)); Assert.That(model.TotalQuantity, Is.EqualTo(0)); }
public async void GameListWithOrders_ContainsNoOrders() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Game>> dbGameStub = TestHelpers.GetFakeAsyncDbSet(new List<Game>().AsQueryable()); dbStub.Setup(db => db.Games).Returns(dbGameStub.Object); Mock<DbSet<WebOrder>> dbWebOrdersStub = TestHelpers.GetFakeAsyncDbSet(new List<WebOrder>().AsQueryable()); dbStub.Setup(db => db.WebOrders).Returns(dbWebOrdersStub.Object); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.GameList() as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<DateFilteredListViewModel<GameListRowViewModel>>()); var model = (DateFilteredListViewModel<GameListRowViewModel>)result.Model; var items = model.Items; Assert.That(items.Count, Is.EqualTo(0)); }
public async void Sales_NoOrders_TotalsAreZero() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<WebOrder>> orderDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<WebOrder>().AsQueryable()); dbStub.Setup(db => db.WebOrders).Returns(orderDbSetStub.Object); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.Sales() as ViewResult; Assert.That(result != null); var model = (SalesViewModel)result.Model; Assert.That(model.OrderCount, Is.EqualTo(0)); Assert.That(model.TotalQuantity, Is.EqualTo(0)); Assert.That(model.ItemsSum, Is.EqualTo(0)); Assert.That(model.ShippingSum, Is.EqualTo(0)); Assert.That(model.TaxSum, Is.EqualTo(0)); Assert.That(model.Total, Is.EqualTo(0)); }
public async void DateFilter_MemberWithSomeOrdersInDateRange_SetsCorrectAverageOrderTotal() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); SetupVeilDataAccessWithUser(dbStub, memberUser); SetupVeilDataAccessWithWebOrders(dbStub, new List<WebOrder> { new WebOrder { MemberId = memberId, OrderSubtotal = 1m, TaxAmount = 0m, ShippingCost = 1m, OrderDate = new DateTime(2015, 11, 22) }, /* $2 */ new WebOrder { MemberId = memberId, OrderSubtotal = 10m, TaxAmount = 10m, ShippingCost = 10m, OrderDate = new DateTime(2010, 01, 01) }, /* $30 */ new WebOrder { MemberId = memberId, OrderSubtotal = 2m, TaxAmount = 0m, ShippingCost = 2m, OrderDate = new DateTime(2015, 11, 22) }, /* $4 */ new WebOrder { MemberId = memberId, OrderSubtotal = 10m, TaxAmount = 10m, ShippingCost = 10m, OrderDate = new DateTime(2010, 01, 01) } /* $30 */ }); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.MemberList(start: new DateTime(2015, 11, 22), optionalEnd: new DateTime(2015, 11, 22)) as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<DateFilteredListViewModel<MemberListItemViewModel>>()); var model = (DateFilteredListViewModel<MemberListItemViewModel>)result.Model; var items = model.Items; Assert.That(items.First().AverageOrderTotal, Is.EqualTo(3m)); }
public async void DateFilter_MemberWithOrders_SetsCorrectTotalSpentOnOrders() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); SetupVeilDataAccessWithUser(dbStub, memberUser); SetupVeilDataAccessWithWebOrders(dbStub, new List<WebOrder> { new WebOrder { MemberId = memberId, OrderSubtotal = 5m, TaxAmount = 5m, ShippingCost = 10m, OrderDate = new DateTime(2015, 11, 22) }, new WebOrder { MemberId = memberId, OrderSubtotal = 5m, TaxAmount = 5m, ShippingCost = 10m, OrderDate = new DateTime(2015, 11, 22) }, new WebOrder { MemberId = memberId, OrderSubtotal = 5m, TaxAmount = 5m, ShippingCost = 10m, OrderDate = new DateTime(2015, 11, 22) }, new WebOrder { MemberId = memberId, OrderSubtotal = 5m, TaxAmount = 5m, ShippingCost = 10m, OrderDate = new DateTime(2015, 11, 22) }, new WebOrder { MemberId = memberId, OrderSubtotal = 5m, TaxAmount = 5m, ShippingCost = 10m, OrderDate = new DateTime(2015, 11, 22) } }); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.MemberList(start: DateTime.MinValue, optionalEnd: DateTime.MaxValue) as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<DateFilteredListViewModel<MemberListItemViewModel>>()); var model = (DateFilteredListViewModel<MemberListItemViewModel>)result.Model; var items = model.Items; Assert.That(items.First().TotalSpentOnOrders, Is.EqualTo(100m)); }
public async void DateFilter_MemberWithThreeOrdersInDateRange_SetsOrderCountToThree() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); SetupVeilDataAccessWithUser(dbStub, memberUser); SetupVeilDataAccessWithWebOrders(dbStub, new List<WebOrder> { new WebOrder { MemberId = memberId, OrderDate = new DateTime(2015, 11, 22) }, new WebOrder { MemberId = memberId, OrderDate = new DateTime(2010, 01, 01) }, new WebOrder { MemberId = memberId, OrderDate = new DateTime(2015, 11, 22) }, new WebOrder { MemberId = memberId, OrderDate = new DateTime(2015, 11, 22) }, new WebOrder { MemberId = memberId, OrderDate = new DateTime(2010, 01, 01) } }); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.MemberList(start: new DateTime(2015, 11, 22), optionalEnd: new DateTime(2015, 11, 22)) as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<DateFilteredListViewModel<MemberListItemViewModel>>()); var model = (DateFilteredListViewModel<MemberListItemViewModel>)result.Model; var items = model.Items; Assert.That(items.First().OrderCount, Is.EqualTo(3)); }
public async void DateFilter_MemberWithNoOrders_SetsTotalSpentOnOrders0() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); SetupVeilDataAccessWithUser(dbStub, memberUser); SetupVeilDataAccessWithWebOrders(dbStub, new List<WebOrder>()); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.MemberList(start: DateTime.MinValue, optionalEnd: DateTime.MinValue) as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<DateFilteredListViewModel<MemberListItemViewModel>>()); var model = (DateFilteredListViewModel<MemberListItemViewModel>)result.Model; var items = model.Items; Assert.That(items.First().TotalSpentOnOrders, Is.EqualTo(0)); }
public async void TwoMembersWithDifferentTotals_OrdersByTotalSpentDescending() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); SetupVeilDataAccessWithUser(dbStub, memberUser, memberUser2); SetupVeilDataAccessWithWebOrders(dbStub, new List<WebOrder> { new WebOrder { MemberId = memberId, OrderSubtotal = 10m, TaxAmount = 10m, ShippingCost = 10m }, new WebOrder { MemberId = memberId2, OrderSubtotal = 5m, TaxAmount = 5m, ShippingCost = 5m } }); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.MemberList() as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<DateFilteredListViewModel<MemberListItemViewModel>>()); var model = (DateFilteredListViewModel<MemberListItemViewModel>)result.Model; var items = model.Items; Assert.That(items.First().TotalSpentOnOrders, Is.GreaterThanOrEqualTo(items.Last().TotalSpentOnOrders)); Assert.That(items.First().UserName, Is.EqualTo(memberUser.UserName)); Assert.That(items.Last().UserName, Is.EqualTo(memberUser2.UserName)); }
public async void Wishlist_GameWithProducts_Wishlisted_IsInModel_SubtotalsMatch() { var platforms = new List<Platform> { new Platform { PlatformCode = "TPlat", PlatformName = "Test Platform" }, new Platform { PlatformCode = "OTPlat", PlatformName = "Other Test Platform" }, }; List<GameProduct> products = new List<GameProduct> { new PhysicalGameProduct { Id = new Guid("D9825FE1-F575-4C36-ACAA-98BA71FACFA8"), Platform = platforms[0] }, new PhysicalGameProduct { Id = new Guid("F546AD43-58C8-44FE-9799-ACC7F0B6368E"), Platform = platforms[1] } }; var game = new Game { Id = new Guid("09BD7D30-5268-4A02-A400-1F302040B6AA"), GameSKUs = products }; platforms[0].GameProducts = new List<GameProduct> { products[0] }; platforms[1].GameProducts = new List<GameProduct> { products[1] }; var members = new List<Member> { new Member { UserId = new Guid("1369019C-8F25-427A-A8F1-00287247D4AE"), Wishlist = new List<Product> { products[0] } }, new Member { UserId = new Guid("D814D26E-AD33-48C5-9518-EA43B75AE5AC"), Wishlist = new List<Product> { products[0], products[1] } } }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { game }.AsQueryable()); dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object); Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(platforms.AsQueryable()); dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object); Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(members.AsQueryable()); dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.Wishlist() as ViewResult; Assert.That(result != null); var model = (WishlistViewModel)result.Model; Assert.That(model.Games.Count(), Is.EqualTo(1)); Assert.That(model.Games.First().WishlistCount, Is.EqualTo(3)); Assert.That(model.Platforms.First(p => p.Platform.PlatformCode == "TPlat").WishlistCount, Is.EqualTo(2)); Assert.That(model.Platforms.First(p => p.Platform.PlatformCode == "OTPlat").WishlistCount, Is.EqualTo(1)); Assert.That(model.WishlistCount, Is.EqualTo(3)); }
public void Index_WhenCalled_ReturnsIndexView() { ReportsController controller = new ReportsController(null); var result = controller.Index() as ViewResult; Assert.That(result != null); }
public async void DateFilter_StartAndEndDate_SetsStartDateToMidnight() { DateTime start = new DateTime(2015, 11, 21); DateTime end = new DateTime(2015, 11, 22); Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); SetupVeilDataAccessWithUser(dbStub, memberUser, memberUser2); SetupVeilDataAccessWithWebOrders(dbStub, new List<WebOrder>()); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.MemberList(start, end) as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<DateFilteredListViewModel<MemberListItemViewModel>>()); var model = (DateFilteredListViewModel<MemberListItemViewModel>)result.Model; Assert.That(model.StartDate.HasValue); Assert.That(model.StartDate.Value, Is.EqualTo(start)); Assert.That(model.EndDate.HasValue); }
public void WishlistDetail_GameIdIsNull_Throws404Exception() { var controller = new ReportsController(null); Assert.That(async () => await controller.WishlistDetail(null), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(ex => ex.GetHttpCode() == 404)); }
public void MemberDetailDateFiltered_UserNotFound_Throws404Exception() { DateTime startDate = new DateTime(635847641516896833L, DateTimeKind.Local); Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member>().AsQueryable()); dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object); ReportsController controller = new ReportsController(dbStub.Object); Assert.That(async () => await controller.MemberDetail("notFound", startDate, end: null), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(ex => ex.GetHttpCode() == 404)); }
public async void GameDetailWithOrders_CorrectQuantitiesAndSales() { Guid gameId = new Guid("40D655DF-FB62-4FD5-8065-A81C9868B145"); Guid productId = new Guid("9AEE5E2E-378D-4828-B142-F69B81C53D8C"); int newQty = 1; decimal newPrice = 9.99m; int usedQty = 2; decimal usedPrice = 0.99m; GameProduct gameProduct = new PhysicalGameProduct { Id = productId, GameId = gameId }; Game game = new Game { GameSKUs = new List<GameProduct> { gameProduct } }; WebOrder webOrder = new WebOrder { OrderItems = new List<OrderItem> { new OrderItem { Product = gameProduct, ProductId = gameProduct.Id, IsNew = true, Quantity = newQty, ListPrice = newPrice }, new OrderItem { Product = gameProduct, ProductId = gameProduct.Id, IsNew = false, Quantity = usedQty, ListPrice = usedPrice } }, OrderStatus = OrderStatus.Processed }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Game>> dbGameStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { game }.AsQueryable()); dbStub.Setup(db => db.Games).Returns(dbGameStub.Object); Mock<DbSet<GameProduct>> dbGameProductStub = TestHelpers.GetFakeAsyncDbSet(new List<GameProduct> { gameProduct }.AsQueryable()); dbStub.Setup(db => db.GameProducts).Returns(dbGameProductStub.Object); Mock<DbSet<WebOrder>> dbWebOrdersStub = TestHelpers.GetFakeAsyncDbSet(new List<WebOrder> { webOrder }.AsQueryable()); dbStub.Setup(db => db.WebOrders).Returns(dbWebOrdersStub.Object); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.GameDetail(gameId) as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<GameDetailViewModel>()); var model = (GameDetailViewModel)result.Model; decimal totalNewSales = newPrice*newQty; decimal totalUsedSales = usedPrice*usedQty; Assert.That(model.TotalNewSales, Is.EqualTo(totalNewSales)); Assert.That(model.TotalUsedSales, Is.EqualTo(totalUsedSales)); Assert.That(model.TotalSales, Is.EqualTo(totalNewSales + totalUsedSales)); Assert.That(model.TotalNewQuantity, Is.EqualTo(newQty)); Assert.That(model.TotalUsedQuantity, Is.EqualTo(usedQty)); Assert.That(model.TotalQuantity, Is.EqualTo(newQty + usedQty)); }
public async void DateFilter_TwoMembersWithSameTotals_ThenOrdersByAverageOrderDescendingOfOrdersInDateRange() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); SetupVeilDataAccessWithUser(dbStub, memberUser, memberUser2); SetupVeilDataAccessWithWebOrders(dbStub, new List<WebOrder> { new WebOrder { MemberId = memberId, OrderSubtotal = 10m, TaxAmount = 10m, ShippingCost = 10m, OrderDate = new DateTime(2015, 11, 22) }, new WebOrder { MemberId = memberId, OrderSubtotal = 10m, TaxAmount = 10m, ShippingCost = 10m, OrderDate = new DateTime(2010, 01, 01) }, new WebOrder { MemberId = memberId2, OrderSubtotal = 5m, TaxAmount = 5m, ShippingCost = 5m, OrderDate = new DateTime(2015, 11, 22) }, new WebOrder { MemberId = memberId2, OrderSubtotal = 5m, TaxAmount = 5m, ShippingCost = 5m, OrderDate = new DateTime(2015, 11, 22) }, new WebOrder { MemberId = memberId2, OrderSubtotal = 5m, TaxAmount = 5m, ShippingCost = 5m, OrderDate = new DateTime(2010, 01, 01) } }); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.MemberList(start: new DateTime(2015, 11, 22), optionalEnd: new DateTime(2015, 11, 22)) as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<DateFilteredListViewModel<MemberListItemViewModel>>()); var model = (DateFilteredListViewModel<MemberListItemViewModel>)result.Model; var items = model.Items; Assert.That(items.First().TotalSpentOnOrders, Is.GreaterThan(0)); Assert.That(items.First().TotalSpentOnOrders, Is.EqualTo(items.Last().TotalSpentOnOrders)); Assert.That(items.First().AverageOrderTotal, Is.GreaterThanOrEqualTo(items.Last().AverageOrderTotal)); Assert.That(items.First().UserName, Is.EqualTo(memberUser.UserName)); Assert.That(items.Last().UserName, Is.EqualTo(memberUser2.UserName)); }
public async void Sales_WithOrders_ReturnsMatchingModel() { List<WebOrder> orders = new List<WebOrder> { new WebOrder { Id = 1, OrderSubtotal = 10m, ShippingCost = 12m, TaxAmount = 1.13m, OrderItems = new List<OrderItem> { new OrderItem { Quantity = 1 } }, Member = new Member { UserAccount = new User { UserName = "******" } } }, new WebOrder { Id = 2, OrderSubtotal = 20m, ShippingCost = 12m, TaxAmount = 2.26m, OrderItems = new List<OrderItem> { new OrderItem { Quantity = 2 } }, Member = new Member { UserAccount = new User { UserName = "******" } } } }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<WebOrder>> orderDbSetStub = TestHelpers.GetFakeAsyncDbSet(orders.AsQueryable()); dbStub.Setup(db => db.WebOrders).Returns(orderDbSetStub.Object); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.Sales() as ViewResult; Assert.That(result != null); var model = (SalesViewModel)result.Model; Assert.That(model.OrderCount, Is.EqualTo(2)); Assert.That(model.TotalQuantity, Is.EqualTo(3)); Assert.That(model.ItemsSum, Is.EqualTo(30m)); Assert.That(model.ShippingSum, Is.EqualTo(24m)); Assert.That(model.TaxSum, Is.EqualTo(3.39m)); Assert.That(model.Total, Is.EqualTo(30m + 24m + 3.39m)); }
public async void DateFilter_NullEndDate_DefaultsToTodayAtJustBeforeMidnight() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); SetupVeilDataAccessWithUser(dbStub, memberUser, memberUser2); SetupVeilDataAccessWithWebOrders(dbStub, new List<WebOrder>()); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.MemberList(start: new DateTime(2015, 11, 21), optionalEnd: null) as ViewResult; Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<DateFilteredListViewModel<MemberListItemViewModel>>()); var model = (DateFilteredListViewModel<MemberListItemViewModel>)result.Model; Assert.That(model.EndDate.HasValue); Assert.That(model.EndDate.Value, Is.EqualTo(DateTime.Today.AddDays(1)).Within(1).Seconds); }
public void WishlistDetail_GameIsNotFound_Throws404Exception() { var platforms = new List<Platform> { new Platform { PlatformCode = "TPlat", PlatformName = "Test Platform" }, new Platform { PlatformCode = "OTPlat", PlatformName = "Other Test Platform" }, }; List<GameProduct> products = new List<GameProduct> { new PhysicalGameProduct { Id = new Guid("D9825FE1-F575-4C36-ACAA-98BA71FACFA8"), Platform = platforms[0] }, new PhysicalGameProduct { Id = new Guid("F546AD43-58C8-44FE-9799-ACC7F0B6368E"), Platform = platforms[1] } }; var game = new Game { Id = new Guid("09BD7D30-5268-4A02-A400-1F302040B6AA"), GameSKUs = products }; platforms[0].GameProducts = new List<GameProduct> { products[0] }; platforms[1].GameProducts = new List<GameProduct> { products[1] }; var members = new List<Member> { new Member { UserId = new Guid("1369019C-8F25-427A-A8F1-00287247D4AE"), Wishlist = new List<Product> { products[0] } }, new Member { UserId = new Guid("D814D26E-AD33-48C5-9518-EA43B75AE5AC"), Wishlist = new List<Product> { products[0], products[1] } } }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> { game }.AsQueryable()); dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object); Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(platforms.AsQueryable()); dbStub.Setup(db => db.Platforms).Returns(platformDbSetStub.Object); Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(members.AsQueryable()); dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object); ReportsController controller = new ReportsController(dbStub.Object); Assert.That(async () => await controller.WishlistDetail(new Guid("9E073E71-1A1E-4B51-A4CA-AE820BEBEA91")), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(ex => ex.GetHttpCode() == 404)); }
public async void MemberDetail_UserFound_ReturnsMatchingModel() { var member = new Member { UserAccount = new User { UserName = "******", FirstName = "Test", LastName = "User" }, FavoriteTags = new List<Tag>(), FavoritePlatforms = new List<Platform>(), Wishlist = new List<Product>(), ReceivedFriendships = new List<Friendship>(), RequestedFriendships = new List<Friendship>(), WebOrders = new List<WebOrder> { new WebOrder { OrderItems = new List<OrderItem> { new OrderItem { Quantity = 1, ListPrice = 10m } }, OrderSubtotal = 10m, ShippingCost = 0m, TaxAmount = 0m, OrderStatus = OrderStatus.UserCancelled }, new WebOrder { OrderItems = new List<OrderItem> { new OrderItem { Quantity = 2, ListPrice = 10m } }, OrderSubtotal = 20m, ShippingCost = 0m, TaxAmount = 0m, OrderStatus = OrderStatus.Processed } } }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { member }.AsQueryable()); dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.MemberDetail(member.UserAccount.UserName) as ViewResult; Assert.That(result != null); var model = (MemberDetailViewModel)result.Model; Assert.That(model.FullName, Is.EqualTo("Test User")); Assert.That(model.OrderCount, Is.EqualTo(1)); Assert.That(model.TotalQuantity, Is.EqualTo(2)); Assert.That(model.Total, Is.EqualTo(20m)); }
public async void SalesDateFilter_Sales_ReturnsMatchingModel() { List<WebOrder> orders = new List<WebOrder> { new WebOrder { Id = 1, OrderDate = new DateTime(2015, 10, 10), OrderSubtotal = 10m, ShippingCost = 12m, TaxAmount = 1.13m, OrderItems = new List<OrderItem> { new OrderItem { Quantity = 1 } }, Member = new Member { UserAccount = new User { UserName = "******" } } }, new WebOrder { Id = 2, OrderDate = new DateTime(2014, 10, 10), OrderSubtotal = 20m, ShippingCost = 12m, TaxAmount = 2.26m, OrderItems = new List<OrderItem> { new OrderItem { Quantity = 2 } }, Member = new Member { UserAccount = new User { UserName = "******" } } }, new WebOrder { Id = 3, OrderDate = DateTime.Today.AddDays(1), OrderSubtotal = 20m, ShippingCost = 12m, TaxAmount = 2.26m, OrderItems = new List<OrderItem> { new OrderItem { Quantity = 2 } }, Member = new Member { UserAccount = new User { UserName = "******" } } } }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<WebOrder>> orderDbSetStub = TestHelpers.GetFakeAsyncDbSet(orders.AsQueryable()); dbStub.Setup(db => db.WebOrders).Returns(orderDbSetStub.Object); ReportsController controller = new ReportsController(dbStub.Object); var result = await controller.Sales(new DateTime(2015, 10, 10), null) as ViewResult; Assert.That(result != null); var model = (SalesViewModel)result.Model; Assert.That(model.OrderCount, Is.EqualTo(1)); Assert.That(model.Items[0].OrderNumber, Is.EqualTo(orders[0].Id)); Assert.That(model.StartDate.Value, Is.EqualTo(new DateTime(2015, 10, 10))); Assert.That(model.EndDate.Value, Is.EqualTo(DateTime.Today.AddDays(1)).Within(1).Seconds); }