コード例 #1
0
 public void GetOrderExFaultTest()
 {
     using (var service = ChannelFactoryHelper.GetOrdersFactory(new InstanceContext(this), UserRole.None).CreateChannel())
     {
         var ex = Assert.Catch <FaultException <OrderNotFound> >(() => { service.GetOrderEx(-1); });
         Assert.AreEqual(ex.Detail.OrderId, -1);
     }
 }
コード例 #2
0
ファイル: OrderSecurityTest.cs プロジェクト: dmchernov/wcf
 public void IncorrectPasswordTest()
 {
     using (var service = ChannelFactoryHelper.GetOrdersFactoryForSecurityTests(new InstanceContext(this), "Operator1", "1234567890").CreateChannel())
     {
         Assert.Catch <CommunicationException>(() => service.GetOrders());
         if (service.State == CommunicationState.Faulted)
         {
             service.Abort();
         }
     }
 }
コード例 #3
0
ファイル: OrderSecurityTest.cs プロジェクト: dmchernov/wcf
 public void NonExistsUserTest()
 {
     using (var service = ChannelFactoryHelper.GetOrdersFactoryForSecurityTests(new InstanceContext(this), "Ivan", "123456").CreateChannel())
     {
         Assert.Catch <CommunicationException>(() => service.GetOrders());
         if (service.State == CommunicationState.Faulted)
         {
             service.Abort();
         }
     }
 }
コード例 #4
0
ファイル: OrderSecurityTest.cs プロジェクト: dmchernov/wcf
 public void AccessDeniedTest()
 {
     using (var service = ChannelFactoryHelper.GetOrdersFactory(new InstanceContext(this), UserRole.Operator).CreateChannel())
     {
         var order = new OrdersHelper().AddOrder();
         Assert.Catch <SecurityAccessDeniedException>(() => service.SendOrderToProcess(order.OrderID, DateTime.Now.AddDays(1)));
         if (service.State == CommunicationState.Faulted)
         {
             service.Abort();
         }
     }
 }
コード例 #5
0
        public void SendOrderToCustomerFaultTest()
        {
            var order = new OrdersHelper().AddOrder();

            using (var service = ChannelFactoryHelper.GetOrdersFactory(new InstanceContext(this), UserRole.Manager).CreateChannel())
            {
                var processedOrder = service.SendOrderToProcess(order.OrderID, DateTime.Now);
                var shippedOrder   = service.SendOrderToCustomer(processedOrder.OrderID, DateTime.Now.AddDays(7));

                var ex = Assert.Catch <FaultException <OrderNotInRequiredStatuses> >(() => { service.SendOrderToCustomer(shippedOrder.OrderID, DateTime.Now.AddDays(10)); });
                Assert.True(ex.Detail.RequiredStatuses.Contains(OrderStatus.InProgress) && ex.Detail.RequiredStatuses.Length == 1);
            }
        }
コード例 #6
0
        public void SendOrderToProcessFaultTest()
        {
            var order = new OrdersHelper().AddOrder();

            using (var service = ChannelFactoryHelper.GetOrdersFactory(new InstanceContext(this), UserRole.Manager).CreateChannel())
            {
                var processedOrder = service.SendOrderToProcess(order.OrderID, DateTime.Now);

                var invalidStatusEx = Assert.Catch <FaultException <OrderNotInRequiredStatuses> >(() => { service.SendOrderToProcess(processedOrder.OrderID, DateTime.Now); });
                Assert.True(invalidStatusEx.Detail.RequiredStatuses.Contains(OrderStatus.New) && invalidStatusEx.Detail.RequiredStatuses.Length == 1);

                var invalidDateEx = Assert.Catch <FaultException <InvalidOrderDate> >(() => { service.SendOrderToProcess(processedOrder.OrderID, DateTime.Now.AddDays(-7)); });
                Assert.AreEqual(invalidDateEx.Detail.OrderId, processedOrder.OrderID);
            }
        }
コード例 #7
0
        public void UpdateOrderFaultTest()
        {
            var order = new OrdersHelper().AddOrder();

            using (var service = ChannelFactoryHelper.GetOrdersFactory(new InstanceContext(this), UserRole.Operator | UserRole.Manager).CreateChannel())
            {
                var oldId = order.OrderID;
                order.OrderID = -100;

                Assert.Catch <FaultException <OrderNotFound> >(() => { service.UpdateOrder(order); });

                order.OrderID = oldId;
                order         = service.SendOrderToProcess(order.OrderID, DateTime.Now);

                Assert.Catch <FaultException <OrderNotInRequiredStatuses> >(() => { service.UpdateOrder(order); });
            }
        }
コード例 #8
0
ファイル: OrderServiceTest.cs プロジェクト: dmchernov/wcf
        public void GetOrderEx()
        {
            Order fullOrderData = null;
            var   service       = ChannelFactoryHelper.GetOrdersFactory(new InstanceContext(this)).CreateChannel();

            try
            {
                var orderId = service.GetOrders().First().OrderID;
                fullOrderData = service.GetOrderEx(orderId);
            }
            catch
            {
                if (service.State == CommunicationState.Faulted)
                {
                    service.Abort();
                }
            }

            service.Close();

            Assert.NotNull(fullOrderData);
        }