Beispiel #1
0
        public void CommandBusSend_SendCommandTwice_ConcurrencyExceptionIsRaised()
        {
            // Arrange
            var commandBus = NinjectDependencyResolver.Current.Resolve <ICommandSender <ISingleSignOnToken> >();

            var command = new CreateInventoryItemCommand(Guid.NewGuid(), "New Inventory Item");

            // Act
            DateTime start = DateTime.Now;

            commandBus.Send(command);
            DateTime end = DateTime.Now;

            DateTime start1 = DateTime.Now;

            try
            {
                commandBus.Send(command);
            }
            finally
            {
                DateTime end1 = DateTime.Now;
                Console.WriteLine("Operation took: {0}", end - start);
                Console.WriteLine("Operation second run took: {0}", end1 - start1);
            }
        }
Beispiel #2
0
        public void CommandBusSend_NonExistingUser_NewInventoryItemSummaryEntityCreated()
        {
            // Arrange
            var domainDataStoreFactory = NinjectDependencyResolver.Current.Resolve <IDomainDataStoreFactory>();

            domainDataStoreFactory.GetInventoryItemSummaryDataStore().RemoveAll();
            var commandBus = NinjectDependencyResolver.Current.Resolve <ICommandSender <ISingleSignOnToken> >();

            var command = new CreateInventoryItemCommand(Guid.NewGuid(), "New Inventory Item");

            // Act
            DateTime start = DateTime.Now;

            commandBus.Send(command);
            DateTime end = DateTime.Now;

            // Assert
            IDataStore <InventoryItemSummaryEntity>  dataStore = domainDataStoreFactory.GetInventoryItemSummaryDataStore();
            IEnumerable <InventoryItemSummaryEntity> query     = dataStore.Where(inventoryItem => !inventoryItem.IsLogicallyDeleted && inventoryItem.Rsn == command.Rsn)
                                                                 .AsEnumerable();
            InventoryItemSummaryEntity result = query.Single();

            Assert.AreEqual(command.Rsn, result.Rsn);
            Assert.AreEqual(command.Name, result.Name);
            Console.WriteLine("Operation took: {0}", end - start);
        }
Beispiel #3
0
        public async Task <IActionResult> Create(
            [FromServices] ICommandHandlerAsync <CreateInventoryItemCommand> createCommandHandler,
            CreateInventoryItemCommand createCommand)
        {
            await createCommandHandler.HandleAsync(createCommand);

            return(RedirectToAction("Index"));
        }
 public void CreateInventoryItem(CreateInventoryItemCommand command)
 {
     _logger.Debug("[inventory] Creating item " + command.Sku);
     _repository.Save(
         new InventoryItem(command.ItemId, command.Sku, command.Description),
         command.Id
         );
     //throw new NotImplementedException();
     _logger.Debug("[inventory] Item " + command.Sku + " saved");
 }
Beispiel #5
0
        public void ExecuteCreateNewInventoryItem(Object state)
        {
            var id      = Guid.NewGuid();
            var command = new CreateInventoryItemCommand(id)
            {
                ItemId      = id,
                Sku         = NewInventoryItemSku,
                Description = NewInventoryItemDescription,
            };

            Infrastructure.Instance.SendCommand(command);
        }
Beispiel #6
0
        partial void OnCreate(IServiceRequestWithData <ISingleSignOnToken, InventoryItemServiceCreateParameters> serviceRequest, ref IServiceResponse results)
        {
            UnitOfWorkService.SetCommitter(this);
            InventoryItemServiceCreateParameters item = serviceRequest.Data;

            // The use of Guid.Empty is simply because we use ints as ids
            var command = new CreateInventoryItemCommand(Guid.Empty, item.name);

            CommandSender.Send(command);

            UnitOfWorkService.Commit(this);
            results = new ServiceResponse();
        }
        public HttpResponseMessage Post(CreateInventoryItemCommand createInventoryItem)
        {
            if (!createInventoryItem.Id.HasValue)
            {
                createInventoryItem.Id = Guid.NewGuid();
            }

            _bus.Send(new CreateInventoryItem(createInventoryItem.Id.Value, createInventoryItem.Name));
            var response = Request.CreateResponse(HttpStatusCode.Accepted);

            response.Headers.Location = new Uri(
                new Uri(Request.RequestUri.ToString().TrimEnd('/') + "/"),
                createInventoryItem.Id.ToString());
            return(response);
        }
        public void Execute_InvetoryItemCreate_NewCreated()
        {
            // Arrange
            var expectedId = Guid.NewGuid();
            var name       = "Crunch Chocolate";
            var command    = new CreateInventoryItemCommand(expectedId, name);

            var bus          = container.Resolve <IBus>();
            var queryService = container.Resolve <IRepositoryForEventSource <InventoryItem> >();

            // Act
            bus.Dispatch(command);

            // Assert
            Assert.AreEqual(name, queryService.GetById(expectedId).Name);
        }
Beispiel #9
0
        public void Handle(CreateInventoryItemCommand command)
        {
            var item = new InventoryItem(command.InventoryItemId, command.Name);

            _repository.Save(item, -1);
        }
        public void Handle(CreateInventoryItemCommand message)
        {
            var item = new InventoryItem(message.InventoryItemId, message.Name);

            _store.Save(item);
        }