Example #1
0
        private async Task <IInventoryRepository> GetAndRegisterInventoryRepository(IServiceProvider provider)
        {
            var item = A.New <InventoryItem>();

            for (int i = 0; i < 10; i++)
            {
                CreateInventory cmd = new CreateInventory(new InventoryId(i, DateTimeOffset.Now), i, item, new[]
                {
                    new InventoryConstraint(InventoryConstraintType.MaxQty, "10", TypeCode.Int32),
                });
                this.inventories.Add(Inventory.Create(cmd));
            }

            List <Task> saveTasks  = new List <Task>();
            var         repository = new InventoryRepository(provider.GetService <IRepository <Inventory, InventoryId> >());

            foreach (var inventory in this.inventories)
            {
                saveTasks.Add(repository.Save(inventory));
            }

            await Task.WhenAll(saveTasks);

            return(repository);
        }
        public IActionResult OnGetCreate()
        {
            var createInventory = new CreateInventory();

            createInventory.Products = _productApplication.GetProducts();
            return(Partial("./Create", createInventory));
        }
Example #3
0
        /// <summary>
        /// persists the inventory information
        /// </summary>
        /// <param name="inv"></param>
        public void Create(CreateInventory inv)
        {
            InventorySvc inventorySvc =
                (InventorySvc)GetService(typeof(InventorySvc));

            inventorySvc.CreateInventory(inv);
        }
Example #4
0
        public IActionResult OnGetCreate()
        {
            var command = new CreateInventory
            {
                Products = _productApplication.GetProducts()
            };

            return(Partial("./Create", command));
        }
Example #5
0
 void Start()
 {
     inven     = (CreateInventory)FindObjectOfType(typeof(CreateInventory));
     checkitem = (Check_Item)FindObjectOfType(typeof(Check_Item));
     if (what_code_item_can_get == "#00x-xx")
     {
         this.gameObject.name = My_Slot_Number.ToString();
     }
 }
Example #6
0
 void Start()
 {
     createinven = (CreateInventory)FindObjectOfType(typeof(CreateInventory));
     check_Item  = (Check_Item)FindObjectOfType(typeof(Check_Item));
     This_Button = this.gameObject.GetComponent <Button>();
     This_Button.interactable = false;
     Check_Item_For_Craft();
     Chang_Pic();
 }
Example #7
0
        public CreateInventoryViewModel(EFDbContext context)
        {
            _invRepo   = new EFRepository <Inventory>(context);
            _typesRepo = new EFRepository <InventoryType>(context);

            Window window = new CreateInventory(this);

            window.ShowDialog();
        }
Example #8
0
        public void When_CreateInventory_And_ConstraintIsEmpty_Then_ThrowEmptyConstraintException()
        {
            var param = this.GetParameters();
            var cmd   = new CreateInventory(param.id, 27, param.item, null);

            Action action = () => Inventory.Create(cmd);

            action.Should().Throw <AggregateException>()
            .WithInnerException <EmptyConstraintException>();
        }
Example #9
0
        public void WhenCreateInventory_And_ItemIsNull_ThenThrowInventoryItemIsNullException()
        {
            var param = this.GetParameters();
            var cmd   = new CreateInventory(param.id, 27, null, new[] { param.constraint });

            Action action = () => Inventory.Create(cmd);

            action.Should().Throw <AggregateException>()
            .WithInnerException <InventoryItemIsNullException>();
        }
Example #10
0
        public void WhenCreateInventory_And_QtyIsNegativeDigital_ThenThrowNegativeQtyException()
        {
            var param = this.GetParameters();
            var cmd   = new CreateInventory(param.id, -13, param.item, new[] { param.constraint });

            Action action = () => Inventory.Create(cmd);

            action.Should().Throw <AggregateException>()
            .WithInnerException <NegativeQtyException>();
        }
Example #11
0
        public static Inventory Create(CreateInventory cmd)
        {
            var inventory = new Inventory(cmd.Id, cmd.Qty, cmd.Item, cmd.Constraints);

            InventoryPolicy.Verify(inventory);

            inventory.ApplyEvent(new InventoryCreated(inventory.Id, inventory.Qty, inventory.Item, inventory.constraints));

            return(inventory);
        }
Example #12
0
        public void Given_QtyIs17_When_OutboundIs38_Then_ThrowInventoryShortageException()
        {
            var param       = this.GetParameters();
            var createdCmd  = new CreateInventory(param.id, 17, param.item, new[] { param.constraint });
            var outboundCmd = new Outbound(38);
            var actual      = Inventory.Create(createdCmd);

            Action action = () => actual.Outbound(outboundCmd);

            action.Should().Throw <InventoryShortageException>();
        }
Example #13
0
        public void When_OutboundIsNegativeDigital_Then_ThrowAmountIncorrectException()
        {
            var param       = this.GetParameters();
            var createdCmd  = new CreateInventory(param.id, 0, param.item, new[] { param.constraint });
            var outboundCmd = new Outbound(-3);
            var actual      = Inventory.Create(createdCmd);

            Action action = () => actual.Outbound(outboundCmd);

            action.Should().Throw <AmountIncorrectException>();
        }
Example #14
0
        public IActionResult OnPostCreate(CreateInventory command)
        {
            var operationResult = new OperationResult();

            if (ModelState.IsValid)
            {
                operationResult = _inventoryApplication.Create(command);
            }

            return(new JsonResult(operationResult));
        }
Example #15
0
        public void Given_QtyIs26_And_MaxQtyIs50_When_InboundIs30_Then_ThrowOverQtyLimitationException()
        {
            var param      = this.GetParameters(maxQty: 50);
            var createdCmd = new CreateInventory(param.id, 26, param.item, new[] { param.constraint });
            var inboundCmd = new Inbound(30);
            var actual     = Inventory.Create(createdCmd);

            Action action = () => actual.Inbound(inboundCmd);

            action.Should().Throw <OverQtyLimitationException>();
        }
Example #16
0
        public void CreateInventoryWithParameters()
        {
            var param     = this.GetParameters(1, DateTimeOffset.Now.AddDays(-1));
            var cmd       = new CreateInventory(param.id, 2, param.item, new[] { param.constraint });
            var inventory = Inventory.Create(cmd);

            inventory.Id.ToString().Should().Be($"inv-{DateTimeOffset.Now.AddDays(-1):yyyyMMdd}-1");
            inventory.Qty.Should().Be(2);
            inventory.Item.Should().Be(param.item);
            inventory.Constraint.Count.Should().Be(1);
            inventory.Constraint.First().Should().Be(param.constraint);
        }
Example #17
0
        public ServiceTests()
        {
            id = new InventoryId();
            var createdCmd = new CreateInventory(id, 10, new InventoryItem(), new[]
            {
                new InventoryConstraint(InventoryConstraintType.MaxQty, "20", TypeCode.Int32),
            });

            inventory = Inventory.Create(createdCmd);

            mockRepository = Substitute.For <IInventoryRepository>();
            mockRepository.GenerateInventoryId().Returns(id);
        }
Example #18
0
        public void CreateInventory_And_ConstraintTypeIsMaxQty_And_ConstraintValueTypeIsString_Then_ThrowException()
        {
            var param = this.GetParameters(1, DateTimeOffset.Now);
            var cmd   = new CreateInventory(param.id, 1, param.item, new[]
            {
                new InventoryConstraint(InventoryConstraintType.MaxQty, "10", TypeCode.String),
            });

            Action action = () => Inventory.Create(cmd);

            action.Should().ThrowExactly <AggregateException>()
            .WithInnerException <ConstraintValueIncorrectException>();
        }
        private void submitButton_Click(object sender, EventArgs e)
        {
            CreateInventory create = new CreateInventory();

            create.ItemAmount     = textBoxAmount.Text;
            create.ItemCategory   = textBoxCategories.Text;
            create.ItemProperties = textBoxValue.Text;
            create.ItemValue      = textBoxValue.Text;

            InventoryMngr invtryMngr = new InventoryMngr();

            invtryMngr.Create(create);
        }
        public OperationResult Create(CreateInventory command)
        {
            var operation = new OperationResult();

            if (_inventoryrepository.Exists(x => x.ProductId == command.ProductId))
            {
                return(operation.Failed(ApplicationMessages.DuplicatedRecord));
            }
            var inventory = new Inventory(command.ProductId, command.UnitPrice);

            _inventoryrepository.Create(inventory);
            _inventoryrepository.Save();
            return(operation.Succeeded());
        }
        public OperationResult Create(CreateInventory command)
        {
            var operationResult = new OperationResult();

            if (_inventoryRepository.Exists(i => i.ProductId == command.ProductId))
            {
                return(operationResult.Failed(QueryValidationMessage.DuplicateRecord));
            }

            var inventory = new Inventory(command.ProductId, command.UnitPrice);

            _inventoryRepository.Create(inventory);
            _inventoryRepository.SaveChanges();
            return(operationResult.Succeeded());
        }
Example #22
0
        public OperationResult Create(CreateInventory command)
        {
            var operationResult = new OperationResult();

            if (_inventoryRepo.Exists(c => c.ProductId == command.ProductId))
            {
                return(operationResult.Failed(ApplicationMessage.duplicated));
            }

            var inventory = new Inventory(command.ProductId, command.UnitPrice);

            _inventoryRepo.Create(inventory);
            _inventoryRepo.Save();
            return(operationResult.Succeeded());
        }
Example #23
0
        public void should_add_new_inventory()
        {
            ICommandDispatcher dispatcher = resolver.GetInstance <ICommandDispatcher>();
            var command = new CreateInventory(Guid.NewGuid(), "new inv");

            // Act
            dispatcher.Execute(command);

            var repository = new MemoryRepository <Inventory>();
            var inv        = repository.GetAll();

            inv.First().ShouldBeEquivalentTo(new Inventory {
                Id = command.Id, Name = command.Name
            });
        }
Example #24
0
        public void Given_QtyIs37_When_OutboundIs2_ThenQtyIs35()
        {
            var param       = this.GetParameters();
            var expectQty   = 35;
            var createdCmd  = new CreateInventory(param.id, 37, param.item, new[] { param.constraint });
            var outboundCmd = new Outbound(2);

            var actual = Inventory.Create(createdCmd);

            actual.Outbound(outboundCmd);
            var evt = (Outbounded)actual.DomainEvents.Last();

            actual.Qty.Should().Be(expectQty);
            evt.Amount.Should().Be(2);
            evt.Qty.Should().Be(35);
        }
Example #25
0
        public void Given_QtyIs0_When_InboundIs50_Then_QtyIs50()
        {
            var param      = this.GetParameters(maxQty: 50);
            var expectQty  = 50;
            var createdCmd = new CreateInventory(param.id, 0, param.item, new[] { param.constraint });
            var inboundCmd = new Inbound(50);

            var actual = Inventory.Create(createdCmd);

            actual.Inbound(inboundCmd);
            var evt = (Inbounded)actual.DomainEvents.Last();

            actual.Qty.Should().Be(expectQty);
            evt.Amount.Should().Be(50);
            evt.Qty.Should().Be(50);
        }
Example #26
0
        public AboutViewModel()
        {
            Title = "Настройки";

            FillPaladinCommand = new Command(async() =>
            {
                await PaladinSpells.FillSpells();
                await PaladinSpells.FillVengeanceSpells();
            });
            FillXGTECommand = new Command(async() => await PaladinSpells.FillXGTESpells());

            FillBaseCommand    = new Command(async() => await ClericSpells.FillSpells());
            FillForgeCommand   = new Command(async() => await ClericSpells.FillForge());
            FillTempestCommand = new Command(async() => await ClericSpells.FillTempest());

            DropBaseCommand        = new Command(async() => await App.Database.ClearSpellBase());
            CreateClericCommand    = new Command(async() => await CreateCharacter.NewCleric());
            CreateInventoryCommand = new Command(async() => await CreateInventory.NewInventory());
        }
Example #27
0
        public async Task Inbound()
        {
            var createdCmd = new CreateInventory(id, 10, new InventoryItem(), new[]
            {
                new InventoryConstraint(InventoryConstraintType.MaxQty, "20", TypeCode.Int32),
            });
            var result     = Inventory.Create(createdCmd);
            var repository = NSubstitute.Substitute.For <IInventoryRepository>();

            repository.GetBy(Arg.Any <InventoryId>()).Returns(result);
            var msg = new InboundMsg()
            {
                Id = $"inv-{DateTimeOffset.Now:yyyyMMdd}-0", Amount = 10
            };

            var svc    = new InboundSvc(new IdTranslator(), repository);
            var actual = await svc.Handle(msg, new CancellationToken());

            actual.Qty.Should().Be(20);
        }
Example #28
0
        public void should_pass_full_life_cycle()
        {
            // Command
            ICommandDispatcher dispatcher = resolver.GetInstance <ICommandDispatcher>();
            var command = new CreateInventory(Guid.NewGuid(), "new inv");

            // Act
            dispatcher.Execute(command);

            // Query
            IQueryDispatcher queryDispatcher = resolver.GetInstance <IQueryDispatcher>();

            var findInventoryByNameQuery = new FindInventoryByNameQuery("new");

            //  var invs= queryDispatcher.Execute(findInventoryByNameQuery); //
            Inventory[] invs = queryDispatcher.Execute <FindInventoryByNameQuery, Inventory[]>(findInventoryByNameQuery);

            invs.First().ShouldBeEquivalentTo(new Inventory {
                Id = command.Id, Name = command.Name
            });
        }
Example #29
0
        public JsonResult OnPostCreate(CreateInventory command)
        {
            var result = _inventoryApplication.Create(command);

            return(new JsonResult(result));
        }
Example #30
0
 void Start()
 {
     inven = (CreateInventory)FindObjectOfType(typeof(CreateInventory));
 }