Esempio n. 1
0
            public async Task CanUpdateOrderStatus(OrderStatus status)
            {
                // Arrange
                Order order;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo = new Repository <Order>(context);
                    order = await orderRepo.QueryAsNoTracking().FirstAsync();
                }
                var mockHttpContextAccessor = GetMockHttpContextAccessorWithUserInRole(RoleName.Seller);
                var mockAppSettingService   = GetMockAppSettingService();

                // Action
                GetOrderVm updatedOrder;
                string     error;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo = new Repository <Order>(context);

                    var orderService = new OrderService(orderRepo, null, null, null, null, null, null, null, null, null, null, mockHttpContextAccessor.Object, mockAppSettingService.Object);
                    (updatedOrder, error) = await orderService.UpdateStatusAsync(order.Id, status);
                }

                // Assert
                Assert.NotNull(updatedOrder);
                Assert.True(error.IsNullOrEmpty());
                Assert.Equal(status, updatedOrder.OrderStatus);
            }
Esempio n. 2
0
            public async Task WithInvalidId_ShouldReturnError()
            {
                // Arrange
                var   trackingNumber = "840242824093";
                Order order;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo = new Repository <Order>(context);
                    order = await orderRepo.QueryAsNoTracking().FirstAsync();
                }
                var mockHttpContextAccessor = GetMockHttpContextAccessorWithUserInRole(RoleName.Seller);

                // Action
                ActionFeedback feedback;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo    = new Repository <Order>(context);
                    var orderService = new OrderService(orderRepo, null, null, null, null, null, null, null, null, null, null, mockHttpContextAccessor.Object, null);
                    feedback = await orderService.UpdateTrackingNumberAsync(order.Id + 1, trackingNumber);
                }

                // Assert
                Assert.False(feedback.Success);
                Assert.True(feedback.ErrorMessage.HasValue());
            }
Esempio n. 3
0
            public async Task WithCompleteStatus_ShouldUpdateCompletedOn()
            {
                // Arrange
                Order order;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo = new Repository <Order>(context);
                    order = await orderRepo.QueryAsNoTracking().FirstAsync();
                }
                var mockHttpContextAccessor = GetMockHttpContextAccessorWithUserInRole(RoleName.Seller);

                // Action
                GetOrderVm updatedOrder;
                string     error;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo    = new Repository <Order>(context);
                    var orderService = new OrderService(orderRepo, null, null, null, null, null, null, null, null, null, null, mockHttpContextAccessor.Object, null);
                    (updatedOrder, error) = await orderService.UpdateStatusAsync(order.Id, OrderStatus.Complete);
                }

                // Assert
                Assert.NotNull(updatedOrder);
                Assert.True(updatedOrder.CompletedOn.HasValue);
            }
Esempio n. 4
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SimplDbContext dataContext)
        {
            dataContext.Database.Migrate();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStatusCodePagesWithReExecute("/Home/ErrorWithCode/{0}");

            app.UseCustomizedRequestLocalization();
            app.UseCustomizedStaticFiles(env);

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapDynamicControllerRoute <UrlSlugRouteTransformer>("{**slug}");
            });

            app.RunModuleConfigures(env);
        }
            public AddStockAsync()
            {
                _options = new DbContextOptionsBuilder <SimplDbContext>()
                           .UseInMemoryDatabase(databaseName: nameof(AddStockAsync))
                           .Options;

                using (var context = new SimplDbContext(_options))
                {
                    var products = new List <Product> {
                        new Product()
                        {
                            Sku = "1", Stock = 1
                        },
                        new Product()
                        {
                            Sku = "12", Stock = 2
                        },
                        new Product()
                        {
                            Sku = "123", Stock = 3
                        },
                        new Product()
                        {
                            Sku = "1234", Stock = 4
                        },
                        new Product()
                        {
                            Sku = "12345", Stock = 5
                        },
                    };
                    var productRepo = new Repository <Product>(context);
                    productRepo.AddRange(products);
                    productRepo.SaveChanges();
                }
            }
Esempio n. 6
0
            private IList <Product> Init(string dbName)
            {
                _options = new DbContextOptionsBuilder <SimplDbContext>()
                           .UseInMemoryDatabase(databaseName: dbName)
                           .Options;

                IList <Product> addedProducts;

                using (var context = new SimplDbContext(_options))
                {
                    var products = new List <Product> {
                        new Product()
                        {
                            Stock = 10, Price = 11000, Cost = 10000
                        },
                        new Product()
                        {
                            Stock = 20, Price = 15400, Cost = 14000
                        },
                    };
                    var productRepo = new Repository <Product>(context);
                    productRepo.AddRange(products);
                    productRepo.SaveChanges();

                    addedProducts = productRepo.Query().ToList();
                }

                return(addedProducts);
            }
Esempio n. 7
0
            public async Task WithOrderNotFound_ShouldReturnDefault()
            {
                // Arrange
                const long CreatedById = 10;
                long       ownerId;
                long       orderId;
                var        options = new DbContextOptionsBuilder <SimplDbContext>()
                                     .UseInMemoryDatabase(databaseName: nameof(WithOrderNotFound_ShouldReturnDefault))
                                     .Options;

                using (var context = new SimplDbContext(options))
                {
                    var order = new Order {
                        CreatedById = CreatedById
                    };
                    var orderRepo = new Repository <Order>(context);
                    orderRepo.Add(order);
                    orderRepo.SaveChanges();

                    orderId = orderRepo.Query().First().Id;
                }

                // Action
                using (var context = new SimplDbContext(options))
                {
                    var orderRepo    = new Repository <Order>(context);
                    var orderService = new OrderService(orderRepo, null, null, null, null, null, null, null, null, null, null, null, null);

                    ownerId = await orderService.GetOrderOwnerIdAsync(orderId + 1);
                }

                // Assert
                Assert.Equal(default(long), ownerId);
            }
Esempio n. 8
0
            public SearchAsync()
            {
                _options = new DbContextOptionsBuilder <SimplDbContext>()
                           .UseInMemoryDatabase(databaseName: nameof(SearchAsync))
                           .Options;
                using (var context = new SimplDbContext(_options))
                {
                    var role = new Role {
                        Name = RoleName.Customer
                    };
                    var customerA = new User
                    {
                        IsDeleted   = false,
                        FullName    = "John Doe",
                        PhoneNumber = "0123456789",
                        Email       = "*****@*****.**",
                        Roles       = new HashSet <UserRole> {
                            new UserRole {
                                Role = role
                            }
                        },
                        DefaultShippingAddress = new Address {
                            AddressLine1 = "somewhere"
                        }
                    };
                    var customerB = new User
                    {
                        IsDeleted   = true,
                        FullName    = "John Henry",
                        PhoneNumber = "987654321",
                        Email       = "*****@*****.**",
                        Roles       = new HashSet <UserRole> {
                            new UserRole {
                                Role = role
                            }
                        },
                        DefaultShippingAddress = new Address {
                            AddressLine1 = "somewhere else"
                        }
                    };
                    var customers = new List <User> {
                        customerA
                    };
                    var userRepo = new Repository <User>(context);
                    userRepo.AddRange(customers);
                    userRepo.SaveChanges();
                }

                var config = new MapperConfiguration(cfg =>
                {
                    cfg.AddProfile <AutoMapperProfile>();
                });

                _mapper = config.CreateMapper();
            }
            private async Task <Product> GetProductBySkuAsync(string sku)
            {
                using (var context = new SimplDbContext(_options))
                {
                    var productRepo = new Repository <Product>(context);
                    var product     = await productRepo.Query()
                                      .FirstIfAsync(!sku.IsNullOrEmpty(), p => p.Sku == sku);

                    return(product);
                }
            }
Esempio n. 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NotificationRepository"/> class.
        /// </summary>
        public NotificationRepository(SimplDbContext context,
                                      IRepository <NotificationScheme> notificationRepository,
                                      IRepository <NotificationDetail> tenantNotificationRepository,
                                      IRepositoryWithTypedId <UserNotification, Guid> userNotificationRepository,
                                      IRepository <NotificationSubscription> notificationSubscriptionRepository)
        {
            Context = context;

            _notificationSchemeRepository       = notificationRepository;
            _notificationDetailRepository       = tenantNotificationRepository;
            _userNotificationRepository         = userNotificationRepository;
            _notificationSubscriptionRepository = notificationSubscriptionRepository;
        }
Esempio n. 11
0
            private async Task <(bool, string)> AddAsync(string barcode)
            {
                bool   ok;
                string message;

                using (var context = new SimplDbContext(_options))
                {
                    var productRepo    = new Repository <Product>(context);
                    var productService = new ProductService(null, productRepo, null, null, null);
                    (ok, message) = await productService.AddStockAsync(barcode);
                }
                return(ok, message);
            }
Esempio n. 12
0
            public async Task SearchAsync_ShouldNotReturnDeletedCustomer(string query)
            {
                // Arrange

                // Action
                IList <CustomerDto> searchResult;

                using (var context = new SimplDbContext(_options))
                {
                    var userRepo        = new Repository <User>(context);
                    var customerService = new CustomerService(_mapper, null, userRepo);
                    searchResult = (await customerService.SearchAsync(query)).ToList();
                }

                // Assert
                Assert.True(!searchResult.Any());
            }
Esempio n. 13
0
            private (long, IList <Product>) Init(string dbName)
            {
                _options = new DbContextOptionsBuilder <SimplDbContext>()
                           .UseInMemoryDatabase(databaseName: dbName)
                           .Options;

                long            orderId;
                IList <Product> addedProducts;

                using (var context = new SimplDbContext(_options))
                {
                    var products = new List <Product> {
                        new Product()
                        {
                            Stock = 10, Price = 11000, Cost = 10000
                        },
                        new Product()
                        {
                            Stock = 20, Price = 15400, Cost = 14000
                        },
                    };
                    var productRepo = new Repository <Product>(context);
                    productRepo.AddRange(products);
                    productRepo.SaveChanges();
                    addedProducts = productRepo.Query().ToList();

                    var order = new Order
                    {
                        OrderItems = new List <OrderItem> {
                            new OrderItem {
                                Product = products[0]
                            },
                            new OrderItem {
                                Product = products[1]
                            }
                        }
                    };
                    var orderRepo = new Repository <Order>(context);
                    orderRepo.Add(order);
                    orderRepo.SaveChanges();

                    orderId = orderRepo.Query().First().Id;
                }

                return(orderId, addedProducts);
            }
Esempio n. 14
0
            public async Task SearchAsync_ShouldIncludeDefaultShippingAddress()
            {
                // Arrange
                var query = "John";

                // Action
                IList <CustomerDto> searchResult;

                using (var context = new SimplDbContext(_options))
                {
                    var userRepo        = new Repository <User>(context);
                    var customerService = new CustomerService(_mapper, null, userRepo);
                    searchResult = (await customerService.SearchAsync(query)).ToList();
                }

                // Assert
                Assert.True(searchResult.Any());
                Assert.Equal("somewhere", searchResult.First().Address);
            }
Esempio n. 15
0
            public UpdateStatusAsync()
            {
                _options = new DbContextOptionsBuilder <SimplDbContext>()
                           .UseInMemoryDatabase(databaseName: nameof(UpdateStatusAsync))
                           .Options;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo = new Repository <Order>(context);
                    var order     = orderRepo.Query().FirstOrDefault();
                    if (order == null)
                    {
                        var products = new List <Product> {
                            new Product()
                            {
                                Stock = 10, Price = 11000, Cost = 10000
                            },
                            new Product()
                            {
                                Stock = 20, Price = 15400, Cost = 14000
                            },
                        };
                        order = new Order()
                        {
                            OrderStatus    = OrderStatus.Pending,
                            CustomerId     = 10,
                            ShippingAmount = 10000,
                            ShippingCost   = 5000,
                            Discount       = 2000,
                            OrderItems     = new List <OrderItem> {
                                new OrderItem {
                                    Product = products[0], Quantity = 5, ProductPrice = products[0].Price
                                },
                                new OrderItem {
                                    Product = products[1], Quantity = 3, ProductPrice = products[1].Price
                                },
                            }
                        };
                        orderRepo.Add(order);
                        orderRepo.SaveChanges();
                    }
                }
            }
Esempio n. 16
0
            public UpdateTrackingNumberAsync()
            {
                _options = new DbContextOptionsBuilder <SimplDbContext>()
                           .UseInMemoryDatabase(databaseName: nameof(UpdateTrackingNumberAsync))
                           .Options;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo = new Repository <Order>(context);
                    var order     = orderRepo.Query().FirstOrDefault();
                    if (order == null)
                    {
                        order = new Order()
                        {
                            TrackingNumber = "123456789097"
                        };
                        orderRepo.Add(order);
                        orderRepo.SaveChanges();
                    }
                }
            }
Esempio n. 17
0
            public async Task WithCancelledStatus_ShouldResetQuantities()
            {
                // Arrange
                Order order;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo = new Repository <Order>(context);
                    order = await orderRepo.QueryAsNoTracking()
                            .Include(item => item.OrderItems).ThenInclude(item => item.Product)
                            .FirstAsync();
                }
                var mockHttpContextAccessor = GetMockHttpContextAccessorWithUserInRole(RoleName.Seller);

                // Action
                Order  updatedOrder;
                string error;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo    = new Repository <Order>(context);
                    var orderService = new OrderService(orderRepo, null, null, null, null, null, null, null, null, null, null, mockHttpContextAccessor.Object, null);
                    (_, error) = await orderService.UpdateStatusAsync(order.Id, OrderStatus.Cancelled);

                    updatedOrder = await orderRepo.QueryAsNoTracking()
                                   .Include(item => item.OrderItems).ThenInclude(item => item.Product)
                                   .FirstAsync(item => item.Id == order.Id);
                }

                // Assert
                Assert.NotNull(updatedOrder);
                Assert.True(error.IsNullOrEmpty());
                Assert.Equal(OrderStatus.Cancelled, updatedOrder.OrderStatus);

                Assert.Equal(0, updatedOrder.SubTotal);
                Assert.Equal(order.ShippingAmount, updatedOrder.OrderTotal);
                Assert.Equal(order.ShippingCost, updatedOrder.OrderTotalCost);
                Assert.Equal(order.OrderItems[0].Product.Stock + order.OrderItems[0].Quantity, updatedOrder.OrderItems[0].Product.Stock);
                Assert.Equal(order.OrderItems[1].Product.Stock + order.OrderItems[1].Quantity, updatedOrder.OrderItems[1].Product.Stock);
            }
Esempio n. 18
0
            public async Task CanUpdateTrackingNumber()
            {
                // Arrange
                var  trackingNumber = "840242824093";
                long orderId;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo = new Repository <Order>(context);
                    var order     = await orderRepo.QueryAsNoTracking().FirstAsync();

                    orderId = order.Id;
                }
                var mockHttpContextAccessor = GetMockHttpContextAccessorWithUserInRole(RoleName.Seller);

                // Action
                ActionFeedback feedback;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo    = new Repository <Order>(context);
                    var orderService = new OrderService(orderRepo, null, null, null, null, null, null, null, null, null, null, mockHttpContextAccessor.Object, null);
                    feedback = await orderService.UpdateTrackingNumberAsync(orderId, trackingNumber);
                }

                Order updated;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo = new Repository <Order>(context);
                    updated = await orderRepo.QueryAsNoTracking().FirstAsync(item => item.Id == orderId);
                }

                // Assert
                Assert.True(feedback.Success);
                Assert.Equal(trackingNumber, updated.TrackingNumber);
            }
Esempio n. 19
0
 public CommentRepository(SimplDbContext context) : base(context)
 {
 }
 public SameBrandProductRepository(SimplDbContext context) : base(context)
 {
 }
Esempio n. 21
0
 public SqlRepository(SimplDbContext dbContext, ILogger <SqlRepository> logger)
 {
     _dbContext = dbContext;
     _logger    = logger;
 }
Esempio n. 22
0
 public RecentlyViewedProductRepository(SimplDbContext context) : base(context)
 {
 }
Esempio n. 23
0
 public SimplRoleStore(SimplDbContext context) : base(context)
 {
 }
Esempio n. 24
0
 public ActivityRepository(SimplDbContext context) : base(context)
 {
 }
Esempio n. 25
0
            public async Task WithCanceledStatus_ShouldResetOrderItemQuantities()
            {
                // Arrange
                var(orderId, products) = Init("CanUpdateOrder_WithCanceledStatus_ShouldResetOrderItemQuantities");

                var orderRequest = new OrderFormVm()
                {
                    OrderId           = orderId,
                    OrderStatus       = OrderStatus.Cancelled,
                    CustomerId        = 10,
                    ShippingAmount    = 10000,
                    ShippingCost      = 5000,
                    Discount          = 2000,
                    TrackingNumber    = "VAN",
                    PaymentProviderId = 2,
                    OrderItems        = new List <OrderItemVm> {
                        new OrderItemVm {
                            ProductId = products[0].Id, Quantity = 5, ProductPrice = products[0].Price, ProductCost = products[0].Cost
                        },
                        new OrderItemVm {
                            ProductId = products[1].Id, Quantity = 3, ProductPrice = products[1].Price, ProductCost = products[1].Cost
                        },
                    }
                };
                var mockHttpContextAccessor = GetMockHttpContextAccessorWithUserInRole(RoleName.Seller);

                // Action
                ActionFeedback feedback;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo    = new Repository <Order>(context);
                    var productRepo  = new Repository <Product>(context);
                    var orderService = new OrderService(orderRepo, productRepo, null, null, null, null, null, null, null, null, null, mockHttpContextAccessor.Object, null);

                    feedback = await orderService.UpdateOrderAsync(orderRequest);
                }

                Order updatedOrder;

                using (var context = new SimplDbContext(_options))
                {
                    var orderRepo = new Repository <Order>(context);
                    updatedOrder = await orderRepo.QueryAsNoTracking()
                                   .Include(item => item.OrderItems).ThenInclude(item => item.Product)
                                   .FirstOrDefaultAsync(i => i.Id == orderId);
                }

                // Assert
                Assert.True(feedback.Success);
                Assert.NotNull(updatedOrder);
                Assert.Equal(orderRequest.OrderStatus, updatedOrder.OrderStatus);
                Assert.Equal(orderRequest.TrackingNumber, updatedOrder.TrackingNumber);
                Assert.Equal(orderRequest.PaymentProviderId, updatedOrder.PaymentProviderId);

                Assert.Equal(0, updatedOrder.SubTotal);
                Assert.Equal(orderRequest.ShippingAmount, updatedOrder.OrderTotal);
                Assert.Equal(orderRequest.ShippingCost, updatedOrder.OrderTotalCost);

                Assert.Equal(products[0].Stock, updatedOrder.OrderItems[0].Product.Stock);
                Assert.Equal(products[1].Stock, updatedOrder.OrderItems[1].Product.Stock);
            }
Esempio n. 26
0
 public ReplyRepository(SimplDbContext context) : base(context)
 {
 }
Esempio n. 27
0
 public SqlRepository(SimplDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
 public ProductTemplateProductAttributeRepository(SimplDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Esempio n. 29
0
 public SimplUserStore(SimplDbContext context, IdentityErrorDescriber describer) : base(context, describer)
 {
 }
Esempio n. 30
0
 public SimplUserStore(SimplDbContext context) : base(context)
 {
 }