public void ReturnCorrectCollectionCount_AsOutParameter_WhenCalled() { // Arrange Guid userId = Guid.NewGuid(); var user = new ApplicationUser() { Cart = new List <BasePizza>() }; IEnumerable <ApplicationUser> users = new List <ApplicationUser>() { user }; IEnumerable <Pizza> pizzas = Helper.GetPizzas(); IEnumerable <CustomPizza> customPizzas = Helper.GetCustomPizzas(); IEnumerable <Order> orders = new List <Order>() { new Order() }; var pizzaContextMock = new Mock <IPizzaFactoryDbContext>(); var orderContextMock = new Mock <IOrderDbContext>(); var userContextMock = new Mock <IIdentityDbContext>() { CallBase = true }; var mapperMock = new Mock <IMapper>(); var validatorMock = new Mock <IValidator>(); var pizzaDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(pizzas); var customPizzaDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(customPizzas); var userDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(users); var orderDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(orders); userDbSetMock.Setup(u => u.Find(userId.ToString())).Returns(user); userContextMock.Setup(ctx => ctx.Users).Returns(userDbSetMock.Object); pizzaContextMock.Setup(ctx => ctx.Pizzas).Returns(pizzaDbSetMock.Object); pizzaContextMock.Setup(ctx => ctx.CustomPizzas).Returns(customPizzaDbSetMock.Object); orderContextMock.Setup(ctx => ctx.Orders).Returns(orderDbSetMock.Object); IApplicationUserService userService = new ApplicationUserService(userContextMock.Object, pizzaContextMock.Object, orderContextMock.Object, mapperMock.Object, validatorMock.Object); int count = 0; // Act var result = userService.GetAllOrdersWithPaging(out count); // Assert Assert.AreEqual(1, count); }
public void CallValidatorValidatePageSize_WhenCalled() { // Arrange Guid userId = Guid.NewGuid(); var user = new ApplicationUser() { Cart = new List <BasePizza>() }; IEnumerable <ApplicationUser> users = new List <ApplicationUser>() { user }; IEnumerable <Pizza> pizzas = Helper.GetPizzas(); IEnumerable <CustomPizza> customPizzas = Helper.GetCustomPizzas(); IEnumerable <Order> orders = new List <Order>(); var pizzaContextMock = new Mock <IPizzaFactoryDbContext>(); var orderContextMock = new Mock <IOrderDbContext>(); var userContextMock = new Mock <IIdentityDbContext>() { CallBase = true }; var mapperMock = new Mock <IMapper>(); var validatorMock = new Mock <IValidator>(); var pizzaDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(pizzas); var customPizzaDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(customPizzas); var userDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(users); var orderDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(orders); userDbSetMock.Setup(u => u.Find(userId.ToString())).Returns(user); userContextMock.Setup(ctx => ctx.Users).Returns(userDbSetMock.Object); pizzaContextMock.Setup(ctx => ctx.Pizzas).Returns(pizzaDbSetMock.Object); pizzaContextMock.Setup(ctx => ctx.CustomPizzas).Returns(customPizzaDbSetMock.Object); orderContextMock.Setup(ctx => ctx.Orders).Returns(orderDbSetMock.Object); IApplicationUserService userService = new ApplicationUserService(userContextMock.Object, pizzaContextMock.Object, orderContextMock.Object, mapperMock.Object, validatorMock.Object); int count = 0; // Act var result = userService.GetAllOrdersWithPaging(out count); // Assert validatorMock.Verify(v => v.ValidatePageSize(It.IsAny <int>(), It.IsAny <int>()), Times.Once); }
public void ReturnCollection_WithPageSizeNumberOfItems_WhenCalled() { // Arrange Guid userId = Guid.NewGuid(); var user = new ApplicationUser() { Cart = new List <BasePizza>() }; IEnumerable <ApplicationUser> users = new List <ApplicationUser>() { user }; IEnumerable <Pizza> pizzas = Helper.GetPizzas(); IEnumerable <CustomPizza> customPizzas = Helper.GetCustomPizzas(); IEnumerable <Order> orders = new List <Order>() { new Order() { Id = Guid.NewGuid(), CreatedOn = DateTime.Today, Pizzas = new List <BasePizza>(), Customer = new ApplicationUser() }, new Order() { Id = Guid.NewGuid(), CreatedOn = DateTime.Now, Pizzas = new List <BasePizza>(), Customer = new ApplicationUser() } }; var pizzaContextMock = new Mock <IPizzaFactoryDbContext>(); var orderContextMock = new Mock <IOrderDbContext>(); var userContextMock = new Mock <IIdentityDbContext>() { CallBase = true }; var mapper = new Mapper(); var validator = new Validator(); var pizzaDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(pizzas); var customPizzaDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(customPizzas); var userDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(users); var orderDbSetMock = QueryableDbSetMock.GetQueryableMockDbSet(orders); userDbSetMock.Setup(u => u.Find(userId.ToString())).Returns(user); userContextMock.Setup(ctx => ctx.Users).Returns(userDbSetMock.Object); pizzaContextMock.Setup(ctx => ctx.Pizzas).Returns(pizzaDbSetMock.Object); pizzaContextMock.Setup(ctx => ctx.CustomPizzas).Returns(customPizzaDbSetMock.Object); orderContextMock.Setup(ctx => ctx.Orders).Returns(orderDbSetMock.Object); IApplicationUserService userService = new ApplicationUserService(userContextMock.Object, pizzaContextMock.Object, orderContextMock.Object, mapper, validator); int count = 0; int pageSize = 1; int page = 2; // Act var result = userService.GetAllOrdersWithPaging(out count, page, pageSize); // Assert Assert.AreEqual(pageSize, result.Count()); }