Exemple #1
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);
        }
        public virtual IServiceResponseWithResultData <Entities.InventoryItemEntity> GetByRsn(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, InventoryItemServiceGetByRsnParameters> serviceRequest)
        {
            AuthenticationTokenHelper.SetAuthenticationToken(serviceRequest.AuthenticationToken);
            IServiceResponseWithResultData <Entities.InventoryItemEntity> results = null;

            OnGetByRsn(serviceRequest, ref results);
            return(CompleteResponse(results));
        }
Exemple #3
0
        public virtual IServiceResponseWithResultData <IEnumerable <Entities.UserEntity> > GetAll(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, UserServiceGetAllParameters> serviceRequest)
        {
            AuthenticationTokenHelper.SetAuthenticationToken(serviceRequest.AuthenticationToken);
            IServiceResponseWithResultData <IEnumerable <Entities.UserEntity> > results = null;

            OnGetAll(serviceRequest, ref results);
            return(CompleteResponse(results));
        }
Exemple #4
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)));
        }
Exemple #5
0
        public void Login_InvalidCredentials_FailedAuthentication()
        {
            // Arrange
            HttpAuthenticationServiceChannelFactory factory = new HttpAuthenticationServiceChannelFactory();
            IAuthenticationService service = factory.CreateChannel();

            // Act
            IServiceResponseWithResultData <Guid?> actual = service.Login(new ServiceRequestWithData <Guid, AuthenticationService.LoginParameters> {
                Data = new AuthenticationService.LoginParameters {
                    EmailAddress = "*****@*****.**", Password = "******"
                }
            });

            // Assert
            Assert.AreEqual(ServiceResponseStateType.FailedAuthentication, actual.State);
            Assert.IsNull(actual.ResultData);
        }
Exemple #6
0
        public void Login_TestCredentials_Succeeded()
        {
            // Arrange
            HttpAuthenticationServiceChannelFactory factory = new HttpAuthenticationServiceChannelFactory();
            IAuthenticationService service = factory.CreateChannel();

            // Act
            IServiceResponseWithResultData <Guid?> actual = service.Login(new ServiceRequestWithData <Guid, AuthenticationService.LoginParameters> {
                Data = new AuthenticationService.LoginParameters {
                    EmailAddress = "*****@*****.**", Password = "******"
                }
            });

            // Assert
            Assert.AreEqual(ServiceResponseStateType.Succeeded, actual.State);
            Assert.IsNotNull(actual.ResultData);
            Assert.IsTrue(actual.ResultData != Guid.Empty);
        }
Exemple #7
0
        partial void OnGetByRsn(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, UserServiceGetByRsnParameters> serviceRequest, ref IServiceResponseWithResultData <Entities.UserEntity> results)
        {
            // Define Query
            ISingleResultQuery <UserQueryStrategy, Entities.UserEntity> query = QueryFactory.CreateNewSingleResultQuery <UserQueryStrategy, Entities.UserEntity>();

            query.QueryStrategy.WithRsn(serviceRequest.Data.rsn);

            // Retrieve Data, but remember if no items exist, the value is null
            query = UserRepository.Retrieve(query);
            Entities.UserEntity user = query.Result;

            results = new ServiceResponseWithResultData <Entities.UserEntity>(user);
        }
Exemple #8
0
        partial void OnGetAll(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, UserServiceGetAllParameters> serviceRequest, ref IServiceResponseWithResultData <IEnumerable <Entities.UserEntity> > results)
        {
            // Define Query
            ICollectionResultQuery <UserQueryStrategy, Entities.UserEntity> query = QueryFactory.CreateNewCollectionResultQuery <UserQueryStrategy, Entities.UserEntity>();

            // Retrieve Data, but remember if no items exist, the value is null
            query = UserRepository.Retrieve(query);
            IEnumerable <Entities.UserEntity> inventoryItems = query.Result;

            results = new ServiceResponseWithResultData <IEnumerable <Entities.UserEntity> >(inventoryItems);
        }
Exemple #9
0
        partial void OnGetByRsn(IServiceRequestWithData <ISingleSignOnToken, InventoryItemServiceGetByRsnParameters> serviceRequest, ref IServiceResponseWithResultData <InventoryItemEntity> results)
        {
            // Define Query
            ISingleResultQuery <InventoryItemQueryStrategy, InventoryItemEntity> query = QueryFactory.CreateNewSingleResultQuery <InventoryItemQueryStrategy, InventoryItemEntity>();

            query.QueryStrategy.WithRsn(serviceRequest.Data.rsn);

            // Retrieve Data, but remember if no items exist, the value is null
            query = InventoryItemRepository.Retrieve(query);
            InventoryItemEntity inventoryItem = query.Result;

            results = new ServiceResponseWithResultData <InventoryItemEntity>(inventoryItem);
        }
 partial void OnGetByRsn(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, InventoryItemServiceGetByRsnParameters> serviceRequest, ref IServiceResponseWithResultData <Entities.InventoryItemEntity> results);
 partial void OnGetAll(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, InventoryItemServiceGetAllParameters> serviceRequest, ref IServiceResponseWithResultData <IEnumerable <Entities.InventoryItemSummaryEntity> > results);
Exemple #12
0
 partial void OnGetAllOrders(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, OrderServiceGetAllOrdersParameters> serviceRequest, ref IServiceResponseWithResultData <IEnumerable <Entities.OrderEntity> > results);
Exemple #13
0
        partial void OnGetAllOrders(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, OrderServiceGetAllOrdersParameters> serviceRequest, ref IServiceResponseWithResultData <IEnumerable <OrderEntity> > results)
        {
            // Define Query
            ICollectionResultQuery <OrderQueryStrategy, OrderEntity> query = QueryFactory.CreateNewCollectionResultQuery <OrderQueryStrategy, OrderEntity>();

            // Retrieve Data
            query = OrderRepository.Retrieve(query);
            IEnumerable <OrderEntity> orders = query.Result;

            results = new ServiceResponseWithResultData <IEnumerable <OrderEntity> >
            {
                State      = ServiceResponseStateType.Succeeded,
                ResultData = orders
            };
        }
Exemple #14
0
        public virtual IServiceResponseWithResultData <IEnumerable <Entities.InventoryItemSummaryEntity> > GetAll(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, InventoryItemServiceGetAllParameters> serviceRequest)
        {
            AuthenticationTokenHelper.SetAuthenticationToken(serviceRequest.AuthenticationToken);
            CorrelationIdHelper.SetCorrelationId(serviceRequest.CorrelationId);
            IServiceResponseWithResultData <IEnumerable <Entities.InventoryItemSummaryEntity> > results = null;

            OnGetAll(serviceRequest, ref results);
            return(CompleteResponse(results));
        }
Exemple #15
0
        public void GetMessages_EachConversationsFromGet_MoreThanNoItems()
        {
            // Arrange
            HttpConversationServiceChannelFactory factory = new HttpConversationServiceChannelFactory();
            IConversationService service = factory.CreateChannel();
            IServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> > conversations = service.Get(new ServiceRequest <Guid>());

            foreach (ConversationSummaryEntity conversationSummary in conversations.ResultData)
            {
                // Act
                var actual = service.GetMessages(new ServiceRequestWithData <Guid, ConversationService.ConversationParameters> {
                    Data = new ConversationService.ConversationParameters {
                        ConversationRsn = conversationSummary.Rsn
                    }
                });

                // Assert
                Assert.IsTrue(actual.ResultData.Any());
            }
        }
Exemple #16
0
        public void Get_NoParameters_MoreThanNoItems()
        {
            // Arrange
            HttpConversationServiceChannelFactory factory = new HttpConversationServiceChannelFactory();
            IConversationService service = factory.CreateChannel();

            // Act
            IServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> > actual = service.Get(new ServiceRequest <Guid>());

            // Assert
            Assert.IsTrue(actual.ResultData.Any());
        }