Exemplo n.º 1
0
        public void Create_NonExistingUser_NewInventoryItemSummaryEntityCreated()
        {
            // Arrange
            var domainDataStoreFactory = NinjectDependencyResolver.Current.Resolve <IDomainDataStoreFactory>();

            domainDataStoreFactory.GetInventoryItemSummaryDataStore().RemoveAll();
            var authenticationTokenHelper = NinjectDependencyResolver.Current.Resolve <IAuthenticationTokenHelper <ISingleSignOnToken> >();
            ISingleSignOnToken token      = authenticationTokenHelper.GetAuthenticationToken();
            var service = NinjectDependencyResolver.Current.Resolve <IInventoryItemService>();

            var parameters = new ServiceRequestWithData <ISingleSignOnToken, InventoryItemServiceCreateParameters>
            {
                AuthenticationToken = token,
                Data = new InventoryItemServiceCreateParameters {
                    name = "New Inventory Item"
                }
            };

            // Act
            DateTime start = DateTime.Now;

            service.Create(parameters);
            DateTime end = DateTime.Now;

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

            Assert.AreEqual(parameters.Data.name, result.Name);
            Console.WriteLine("Operation took: {0}", end - start);
        }
Exemplo n.º 2
0
        private static IQueryable <OrderViewModel> GetOrders()
        {
            var orderServiceFactory = new HttpOrderServiceChannelFactory();

            IOrderService service  = orderServiceFactory.CreateChannel();
            var           request2 = new ServiceRequestWithData <ISingleSignOnToken, OrderServiceGetAllOrdersParameters>
            {
                AuthenticationToken = new SingleSignOnToken(),
                CorrelationId       = Guid.NewGuid(),
                Data = new OrderServiceGetAllOrdersParameters()
            };

            // Act
            IServiceResponseWithResultData <IEnumerable <OrderEntity> > response = service.GetAllOrders(request2);

            IQueryable <OrderViewModel> orders = response.ResultData.Select(order => new OrderViewModel
            {
                CustomerID     = order.CustomerId,
                OrderID        = order.OrderId,
                EmployeeID     = order.EmployeeId,
                OrderDate      = order.OrderDate,
                ShipCountry    = order.ShipCountry,
                ShipVia        = order.ShipViaId,
                ShippedDate    = order.ShippedDate,
                ShipName       = order.ShipName,
                ShipAddress    = order.ShipAddress,
                ShipCity       = order.ShipCity,
                ShipPostalCode = order.ShipPostalCode
            }).AsQueryable();

            return(orders);
        }
Exemplo n.º 3
0
        public ActionResult Orders_Create([DataSourceRequest] DataSourceRequest request, OrderViewModel order)
        {
            if (ModelState.IsValid)
            {
                order.OrderID = new Random(Guid.NewGuid().GetHashCode()).Next();
                var orderServiceFactory = new HttpOrderServiceChannelFactory();

                IOrderService service  = orderServiceFactory.CreateChannel();
                var           request2 = new ServiceRequestWithData <ISingleSignOnToken, OrderEntity>
                {
                    AuthenticationToken = new SingleSignOnToken(),
                    CorrelationId       = Guid.NewGuid(),
                    Data = new OrderEntity
                    {
                        OrderId        = order.OrderID,
                        CustomerId     = order.CustomerID,
                        EmployeeId     = order.EmployeeID,
                        OrderDate      = order.OrderDate,
                        ShipCountry    = order.ShipCountry,
                        ShipViaId      = order.ShipVia,
                        ShippedDate    = order.ShippedDate,
                        ShipName       = order.ShipName,
                        ShipAddress    = order.ShipAddress,
                        ShipCity       = order.ShipCity,
                        ShipPostalCode = order.ShipPostalCode
                    }
                };

                // Act
                IServiceResponseWithResultData <OrderEntity> response2 = service.CreateOrder(request2);
                Guid correlationId = response2.CorrelationId;

                var request3 = new ServiceRequestWithData <ISingleSignOnToken, Guid>
                {
                    AuthenticationToken = new SingleSignOnToken(),
                    Data = correlationId
                };

                IEnumerable <EventData> result;
                int loopCount = 0;

                // We're using an in-process bus so this isn't actually necassary, but it demonstrates how to wait for the command and event bus to complete their processes
                do
                {
                    // Wait 0.5 of a second and ask again
                    if (loopCount > 0)
                    {
                        System.Threading.Thread.Sleep(500);
                    }

                    IServiceResponseWithResultData <IEnumerable <EventData> > response3 = service.GetEventData(request3);
                    result = response3.ResultData;
                    result = result.Where(x => x.EventType == typeof(OrderCreated).AssemblyQualifiedName);
                } while (!result.Any() && loopCount++ < 10);
            }
            return(Json(new[] { order }.ToDataSourceResult(request, ModelState)));
        }
Exemplo n.º 4
0
        public ActionResult DtoIndex()
        {
            CorrolationIdHelper.SetCorrolationId(Guid.NewGuid());
            ServiceRequestWithData <ISingleSignOnToken, UserServiceGetAllParameters> parameters = new ServiceRequestWithData <ISingleSignOnToken, UserServiceGetAllParameters>
            {
                AuthenticationToken = GetAuthenticationToken(),
                Data = new UserServiceGetAllParameters()
            };

            ViewData.Model = UserService.GetAll(parameters).ResultData;
            return(View());
        }
Exemplo n.º 5
0
        public ActionResult DtoAdd(string name)
        {
            CorrolationIdHelper.SetCorrolationId(Guid.NewGuid());
            ServiceRequestWithData <ISingleSignOnToken, Domain.Authentication.Entities.UserEntity> parameters = new ServiceRequestWithData <ISingleSignOnToken, Domain.Authentication.Entities.UserEntity>
            {
                AuthenticationToken = GetAuthenticationToken(),
                Data = new Domain.Authentication.Entities.UserEntity {
                    Name = name
                }
            };

            UserService.CreateUser(parameters);

            return(RedirectToAction("DtoIndex"));
        }
Exemplo n.º 6
0
        public ActionResult DtoDetails(Guid id)
        {
            CorrolationIdHelper.SetCorrolationId(Guid.NewGuid());
            ServiceRequestWithData <ISingleSignOnToken, UserServiceGetByRsnParameters> parameters = new ServiceRequestWithData <ISingleSignOnToken, UserServiceGetByRsnParameters>
            {
                AuthenticationToken = GetAuthenticationToken(),
                Data = new UserServiceGetByRsnParameters {
                    rsn = id
                }
            };

            ViewData.Model = UserService.GetByRsn(parameters).ResultData;
            return(View());
        }
Exemplo n.º 7
0
        public ActionResult Remove(Guid id, int number)
        {
            CorrolationIdHelper.SetCorrolationId(Guid.NewGuid());
            ServiceRequestWithData <ISingleSignOnToken, InventoryItemServiceRemoveParameters> parameters = new ServiceRequestWithData <ISingleSignOnToken, InventoryItemServiceRemoveParameters>
            {
                AuthenticationToken = GetAuthenticationToken(),
                Data = new InventoryItemServiceRemoveParameters {
                    rsn = id, count = number
                }
            };

            InventoryItemService.Remove(parameters);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 8
0
        public ActionResult ChangeName(Guid id, string name)
        {
            CorrolationIdHelper.SetCorrolationId(Guid.NewGuid());
            ServiceRequestWithData <ISingleSignOnToken, InventoryItemServiceChangeNameParameters> parameters = new ServiceRequestWithData <ISingleSignOnToken, InventoryItemServiceChangeNameParameters>
            {
                AuthenticationToken = GetAuthenticationToken(),
                Data = new InventoryItemServiceChangeNameParameters {
                    rsn = id, newName = name
                }
            };

            InventoryItemService.ChangeName(parameters);

            return(RedirectToAction("Index"));
        }