Example #1
0
        public async void ReturnTrue_AllProductsWasInStock()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "ReturnTrue_AllProductsWasInStock")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                var unitOfWork = new UnitOfWork <ApplicationDbContext>(context);
                unitOfWork.Repository.Add(new InventoryProduct()
                {
                    Amount = 5, Id = 1, ProductId = 1, Price = 10.0
                });

                await unitOfWork.SaveChanges();

                var command = new CheckInventoryCommand(new List <int>()
                {
                    1
                });

                var handler = new CheckInventoryCommandHandler(unitOfWork);

                var result = handler.Handle(command, new CancellationToken()).Result;
                Assert.True(result.Succes);
            }
        }
        public async Task WhenIPressPerchauseAsync()
        {
            CancellationToken handleToken = new CancellationToken();

            _checkHandler = new CheckInventoryCommandHandler(unitOfWorkMock.Object);
            result        = await _checkHandler.Handle(_checkInventory, handleToken);
        }
Example #3
0
        public void ArgumentOutOfRangeException_ProductIdsEmpty()
        {
            var command = new CheckInventoryCommand(new List <int>());

            var handler = new CheckInventoryCommandHandler(this._unitOfwork.Object);

            Assert.ThrowsAnyAsync <ArgumentOutOfRangeException>(() => handler.Handle(command, new CancellationToken()));
        }
Example #4
0
        public void ThrowArgumentNullException_ProductIdsNull()
        {
            var command = new CheckInventoryCommand(null);

            var handler = new CheckInventoryCommandHandler(this._unitOfwork.Object);

            Assert.ThrowsAnyAsync <ArgumentNullException>(() => handler.Handle(command, new CancellationToken()));
        }
Example #5
0
        public void ReturnNull_NullReturFromDB()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "ReturnNull_NullReturFromDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                var unitOfWork = new UnitOfWork <ApplicationDbContext>(context);

                var command = new CheckInventoryCommand(new List <int>()
                {
                    1, 2, 3
                });

                var handler = new CheckInventoryCommandHandler(unitOfWork);

                Assert.Null(handler.Handle(command, new CancellationToken()).Result);
            }
        }