Exemple #1
0
        public void AddToOneToManyRelationWithOldRelatedObject()
        {
            DomainObjectCollection preloadedOrderItemsOfOrder1 = _order1.OrderItems;

            preloadedOrderItemsOfOrder1.EnsureDataComplete();

            OrderItem newOrderItem           = DomainObjectIDs.OrderItem3.GetObject <OrderItem>();
            Order     oldOrderOfNewOrderItem = newOrderItem.Order;

            oldOrderOfNewOrderItem.EnsureDataAvailable();

            _mockRepository.BackToRecord(_extension);
            var newOrderItemEventReceiver           = _mockRepository.StrictMock <DomainObjectMockEventReceiver> (newOrderItem);
            var oldOrderOfNewOrderItemEventReceiver = _mockRepository.StrictMock <DomainObjectMockEventReceiver> (oldOrderOfNewOrderItem);

            using (_mockRepository.Ordered())
            {
                _extension.RelationReading(
                    TestableClientTransaction, _order1, GetEndPointDefinition(typeof(Order), "OrderItems"), ValueAccess.Current);
                _extension.RelationRead(null, null, null, (ReadOnlyDomainObjectCollectionAdapter <DomainObject>)null, ValueAccess.Current);
                LastCall.Constraints(
                    Is.Same(TestableClientTransaction),
                    Is.Same(_order1),
                    Is.Equal(GetEndPointDefinition(typeof(Order), "OrderItems")),
                    Property.Value("Count", preloadedOrderItemsOfOrder1.Count) & new ContainsConstraint(preloadedOrderItemsOfOrder1),
                    Is.Equal(ValueAccess.Current));

                _extension.RelationChanging(
                    TestableClientTransaction, newOrderItem, GetEndPointDefinition(typeof(OrderItem), "Order"), oldOrderOfNewOrderItem, _order1);
                newOrderItemEventReceiver.RelationChanging(GetEndPointDefinition(typeof(OrderItem), "Order"), oldOrderOfNewOrderItem, _order1);

                _extension.RelationChanging(
                    TestableClientTransaction, _order1, GetEndPointDefinition(typeof(Order), "OrderItems"), null, newOrderItem);
                _order1EventReceiver.RelationChanging(GetEndPointDefinition(typeof(Order), "OrderItems"), null, newOrderItem);

                _extension.RelationChanging(
                    TestableClientTransaction, oldOrderOfNewOrderItem, GetEndPointDefinition(typeof(Order), "OrderItems"), newOrderItem, null);
                oldOrderOfNewOrderItemEventReceiver.RelationChanging(GetEndPointDefinition(typeof(Order), "OrderItems"), newOrderItem, null);


                oldOrderOfNewOrderItemEventReceiver.RelationChanged(GetEndPointDefinition(typeof(Order), "OrderItems"), newOrderItem, null);
                _extension.RelationChanged(
                    TestableClientTransaction, oldOrderOfNewOrderItem, GetEndPointDefinition(typeof(Order), "OrderItems"), newOrderItem, null);

                _order1EventReceiver.RelationChanged(GetEndPointDefinition(typeof(Order), "OrderItems"), null, newOrderItem);
                _extension.RelationChanged(TestableClientTransaction, _order1, GetEndPointDefinition(typeof(Order), "OrderItems"), null, newOrderItem);

                newOrderItemEventReceiver.RelationChanged(GetEndPointDefinition(typeof(OrderItem), "Order"), oldOrderOfNewOrderItem, _order1);
                _extension.RelationChanged(TestableClientTransaction, newOrderItem, GetEndPointDefinition(typeof(OrderItem), "Order"), oldOrderOfNewOrderItem, _order1);
            }

            _mockRepository.ReplayAll();

            _order1.OrderItems.Add(newOrderItem);

            _mockRepository.VerifyAll();
        }
Exemple #2
0
        public void ReplaceInOneToManyRelation()
        {
            Assert.Greater(_order1.OrderItems.Count, 0);
            OrderItem oldOrderItem = _order1.OrderItems[0];

            DomainObjectCollection preloadedOrderItems = _order1.OrderItems;
            OrderItem newOrderItem = OrderItem.NewObject();

            _mockRepository.BackToRecord(_extension);
            var oldOrderItemEventReceiver = _mockRepository.StrictMock <DomainObjectMockEventReceiver> (oldOrderItem);
            var newOrderItemEventReceiver = _mockRepository.StrictMock <DomainObjectMockEventReceiver> (newOrderItem);

            using (_mockRepository.Ordered())
            {
                _extension.RelationReading(
                    TestableClientTransaction, _order1, GetEndPointDefinition(typeof(Order), "OrderItems"), ValueAccess.Current);
                _extension.RelationRead(null, null, null, (ReadOnlyDomainObjectCollectionAdapter <DomainObject>)null, ValueAccess.Current);
                LastCall.Constraints(
                    Is.Same(TestableClientTransaction),
                    Is.Same(_order1),
                    Is.Equal(GetEndPointDefinition(typeof(Order), "OrderItems")),
                    Property.Value("Count", preloadedOrderItems.Count) & new ContainsConstraint(preloadedOrderItems),
                    Is.Equal(ValueAccess.Current));

                _extension.RelationChanging(
                    TestableClientTransaction, oldOrderItem, GetEndPointDefinition(typeof(OrderItem), "Order"), _order1, null);
                oldOrderItemEventReceiver.RelationChanging(GetEndPointDefinition(typeof(OrderItem), "Order"), _order1, null);

                _extension.RelationChanging(
                    TestableClientTransaction, newOrderItem, GetEndPointDefinition(typeof(OrderItem), "Order"), null, _order1);
                newOrderItemEventReceiver.RelationChanging(GetEndPointDefinition(typeof(OrderItem), "Order"), null, _order1);

                _extension.RelationChanging(
                    TestableClientTransaction, _order1, GetEndPointDefinition(typeof(Order), "OrderItems"), oldOrderItem, newOrderItem);
                _order1EventReceiver.RelationChanging(GetEndPointDefinition(typeof(Order), "OrderItems"), oldOrderItem, newOrderItem);

                _order1EventReceiver.RelationChanged(GetEndPointDefinition(typeof(Order), "OrderItems"), oldOrderItem, newOrderItem);
                _extension.RelationChanged(TestableClientTransaction, _order1, GetEndPointDefinition(typeof(Order), "OrderItems"), oldOrderItem, newOrderItem);

                newOrderItemEventReceiver.RelationChanged(GetEndPointDefinition(typeof(OrderItem), "Order"), null, _order1);
                _extension.RelationChanged(TestableClientTransaction, newOrderItem, GetEndPointDefinition(typeof(OrderItem), "Order"), null, _order1);

                oldOrderItemEventReceiver.RelationChanged(GetEndPointDefinition(typeof(OrderItem), "Order"), _order1, null);
                _extension.RelationChanged(TestableClientTransaction, oldOrderItem, GetEndPointDefinition(typeof(OrderItem), "Order"), _order1, null);
            }

            _mockRepository.ReplayAll();

            _order1.OrderItems[0] = newOrderItem;

            _mockRepository.VerifyAll();
        }
Exemple #3
0
        protected override void beforeEach()
        {
            suite = new Suite("the suite");
            test  = new Test("test 1");
            suite.AddTest(test);

            Services.Inject(suite);

            driver = MockRepository.GenerateMock <ITestLineDriver>();
            MockFor <ISuiteView>().Expect(x => x.AddTest(test, null)).Constraints(Is.Equal(test), Is.Anything()).Return(
                driver);

            ClassUnderTest.Activate(null);
        }
        private IControlFactory SetupControlFactoryMockWithExpectationWithDelegate(
            MockRepository mockRepository, string message, string title,
            MessageBoxIcon messageBoxIcon, DialogResult dialogResultToReturn,
            ConfirmationDelegate confirmationDelegate)
        {
            IControlFactory controlFactory = mockRepository.StrictMock <IControlFactory>();

            controlFactory.Expect(
                factory => factory.ShowMessageBox(null, null, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Asterisk, null))
            .Return(dialogResultToReturn).Constraints(
                Is.Equal(message), Is.Equal(title), Is.Equal(MessageBoxButtons.YesNo),
                Is.Equal(messageBoxIcon), Is.Anything())
            .WhenCalled(invocation => confirmationDelegate(dialogResultToReturn == DialogResult.Yes));
            return(controlFactory);
        }
Exemple #5
0
        public void run_the_tests()
        {
            ClassUnderTest.RunAllTests();

            MockFor <IFileSystem>().AssertWasCalled(x => x.DeleteFolder(setup.ResultsFolder));
            MockFor <IFileSystem>().AssertWasCalled(x => x.CreateFolder(setup.ResultsFolder));

            MockFor <IResultsSummary>().AssertWasCalled(x => x.Start(null, DateTime.Now),
                                                        o =>
            {
                o.Constraints(Is.Equal("All Tests in the directory"),
                              Is.TypeOf <DateTime>());
            });

            MockFor <ITestRunner>().AssertWasCalled(x => x.RunTests(tests, ClassUnderTest));
            MockFor <IResultsSummary>().AssertWasCalled(x => x.WriteFile(setup.ResultsFile));
        }
        public void Test_DeleteBusinessObject_ConfirmationMessage()
        {
            //---------------Set up test pack-------------------
            MockRepository mockRepository  = new MockRepository();
            string         boToString      = TestUtil.GetRandomString();
            string         expectedMessage = string.Format("Are you certain you want to delete the object '{0}'", boToString);
            IConfirmer     confirmer       = CreateMockConfirmerWithExpectation(mockRepository,
                                                                                Is.Equal(expectedMessage), false);
            IBusinessObject boToDelete = new MockBOWithToString(boToString);
            ConfirmingBusinessObjectDeletor confirmingBusinessObjectDeletor = new ConfirmingBusinessObjectDeletor(confirmer);

            mockRepository.ReplayAll();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            confirmingBusinessObjectDeletor.DeleteBusinessObject(boToDelete);
            //---------------Test Result -----------------------
            mockRepository.VerifyAll();
        }
        public void Test_DeleteBusinessObject_CustomConfirmationMessage()
        {
            //---------------Set up test pack-------------------
            MockRepository mockRepository  = new MockRepository();
            string         expectedMessage = TestUtil.GetRandomString();
            IConfirmer     confirmer       = CreateMockConfirmerWithExpectation(mockRepository,
                                                                                Is.Equal(expectedMessage), false);
            IBusinessObject boToDelete = mockRepository.StrictMock <IBusinessObject>();
            ConfirmingBusinessObjectDeletor confirmingBusinessObjectDeletor =
                new ConfirmingBusinessObjectDeletor(confirmer, t => expectedMessage);

            mockRepository.ReplayAll();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            confirmingBusinessObjectDeletor.DeleteBusinessObject(boToDelete);
            //---------------Test Result -----------------------
            mockRepository.VerifyAll();
        }
        protected override void beforeEach()
        {
            //NOTE: I'm told that the following 4 lines are the result of making things 'easier to mock'
            var context =
                new RequestContext(
                    new HttpContextWrapper(new HttpContext(new HttpRequest("foo.txt", "http://test", ""),
                                                           new HttpResponse(Console.Out))),
                    new RouteData());

            behaviorId = Guid.NewGuid();
            Services.Inject(behaviorId);

            captured = new CaptureArg();

            MockFor <IBehaviorFactory>()
            .Expect(x => x.BuildBehavior(null, behaviorId))
            .Constraints(captured, Is.Equal(behaviorId))
            .Return(MockFor <IActionBehavior>());

            handler = ClassUnderTest.GetHttpHandler(context);
        }
Exemple #9
0
        protected override void beforeEach()
        {
            suite = StoryTeller.Testing.DataMother.BuildHierarchy(@"
t1,Success
t2,Success
t3,Success
");


            test1 = suite.FindTest("t1");
            test2 = suite.FindTest("t2");
            test3 = suite.FindTest("t3");

            Services.Inject(suite);

            driver1 = MockRepository.GenerateMock <ITestLineDriver>();
            driver2 = MockRepository.GenerateMock <ITestLineDriver>();
            driver3 = MockRepository.GenerateMock <ITestLineDriver>();


            MockFor <ISuiteView>().Expect(x => x.AddTest(null, null)).Constraints(Is.Equal(test1), Is.Anything()).Return(
                driver1);
            MockFor <ISuiteView>().Expect(x => x.AddTest(null, null)).Constraints(Is.Equal(test2), Is.Anything()).Return(
                driver2);
            MockFor <ISuiteView>().Expect(x => x.AddTest(null, null)).Constraints(Is.Equal(test3), Is.Anything()).Return(
                driver3);

            MockFor <ITestService>().Expect(x => x.GetStatus(test1)).Return(TestState.Queued);
            MockFor <ITestExplorer>().Expect(x => x.IconFor(test1)).Return(Icon.Pending);

            MockFor <ITestService>().Expect(x => x.GetStatus(test2)).Return(TestState.NotQueued);
            MockFor <ITestExplorer>().Expect(x => x.IconFor(test2)).Return(Icon.Success);

            MockFor <ITestService>().Expect(x => x.GetStatus(test3)).Return(TestState.NotQueued);
            MockFor <ITestExplorer>().Expect(x => x.IconFor(test3)).Return(Icon.Failed);

            ClassUnderTest.Activate(null);
        }
 /// <summary>
 /// Creates a new <see cref="PublicFieldIs"/> instance, specifying a disambiguating
 /// <paramref name="declaringType"/> for the public field.
 /// </summary>
 /// <param name="declaringType">The type that declares the public field, used to disambiguate between public fields.</param>
 /// <param name="publicFieldName">Name of the public field.</param>
 /// <param name="expectedValue">Expected value.</param>
 public PublicFieldIs(Type declaringType, string publicFieldName, object expectedValue)
     : base(declaringType, publicFieldName, Is.Equal(expectedValue))
 {
 }
 /// <summary>
 /// Creates a new <see cref="PublicFieldIs"/> instance.
 /// </summary>
 /// <param name="publicFieldName">Name of the public field.</param>
 /// <param name="expectedValue">Expected value.</param>
 public PublicFieldIs(string publicFieldName, object expectedValue)
     : base(publicFieldName, Is.Equal(expectedValue))
 {
 }
 /// <summary>
 /// Creates a new <see cref="PropertyIs"/> instance, specifying a disambiguating
 /// <paramref name="declaringType"/> for the property.
 /// </summary>
 /// <param name="declaringType">The type that declares the property, used to disambiguate between properties.</param>
 /// <param name="propertyName">Name of the property.</param>
 /// <param name="expectedValue">Expected value.</param>
 public PropertyIs(Type declaringType, string propertyName, object expectedValue)
     : base(declaringType, propertyName, Is.Equal(expectedValue))
 {
 }
 /// <summary>
 /// Creates a new <see cref="PropertyIs"/> instance.
 /// </summary>
 /// <param name="propertyName">Name of the property.</param>
 /// <param name="expectedValue">Expected value.</param>
 public PropertyIs(string propertyName, object expectedValue)
     : base(propertyName, Is.Equal(expectedValue))
 {
 }
Exemple #14
0
 /// <summary>
 /// Evaluate an equal constraint for <see cref="IComparable"/>.
 /// </summary>
 /// <param name="obj">The object the parameter should equal to</param>
 public T Equal(object obj)
 {
     obj = ConvertObjectTypeToMatch(obj);
     ArgManager.AddInArgument(Is.Equal(obj));
     return(default(T));
 }
Exemple #15
0
 public void should_direct_the_status_bar_to_show_the_recycle_was_finished_and_failed()
 {
     MockFor <IStatusView>().AssertWasCalled(x => x.MarkCycleTime(DateTime.Now, false), x => x.Constraints(Is.TypeOf <DateTime>(), Is.Equal(false)));
 }