コード例 #1
0
        public void TestAtTekstSetterKalderHandleExceptionOnExceptionHandlerViewModelVedExceptions()
        {
            var fixture = new Fixture();

            fixture.Customize <IExceptionHandlerViewModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IExceptionHandlerViewModel>()));

            var exception      = fixture.Create <Exception>();
            var tabelModelMock = MockRepository.GenerateMock <ITabelModelBase>();

            tabelModelMock.Expect(m => m.Tekst = Arg <string> .Is.Anything)
            .Throw(exception)
            .Repeat.Any();

            var exceptionHandleViewModelMock = fixture.Create <IExceptionHandlerViewModel>();

            var tabelViewModel = new MyTabelViewModel(tabelModelMock, exceptionHandleViewModelMock);

            Assert.That(tabelViewModel, Is.Not.Null);

            var newValue = fixture.Create <string>();

            tabelViewModel.Tekst = newValue;

            tabelModelMock.AssertWasCalled(m => m.Tekst = Arg <string> .Is.Equal(newValue));
            exceptionHandleViewModelMock.AssertWasCalled(m => m.HandleException(Arg <Exception> .Is.Equal(exception)));
        }
コード例 #2
0
        public void TestAtPropertyChangedOnTabelModelEventHandlerRejserPropertyChangedOnTabelModelUpdate(string propertyNameToRaise, string expectPropertyName)
        {
            var fixture = new Fixture();

            fixture.Customize <ITabelModelBase>(e => e.FromFactory(() => MockRepository.GenerateMock <ITabelModelBase>()));
            fixture.Customize <IExceptionHandlerViewModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IExceptionHandlerViewModel>()));

            var tabelModelMock = fixture.Create <ITabelModelBase>();
            var exceptionHandleViewModelMock = fixture.Create <IExceptionHandlerViewModel>();

            var tabelViewModel = new MyTabelViewModel(tabelModelMock, exceptionHandleViewModelMock)
            {
                ThrowExceptionInModelChanged = false
            };

            Assert.That(tabelViewModel, Is.Not.Null);
            Assert.That(tabelViewModel.ThrowExceptionInModelChanged, Is.False);

            var eventCalled = false;

            tabelViewModel.PropertyChanged += (s, e) =>
            {
                Assert.That(s, Is.Not.Null);
                Assert.That(e, Is.Not.Null);
                Assert.That(e.PropertyName, Is.Not.Null);
                Assert.That(e.PropertyName, Is.Not.Empty);
                if (string.Compare(e.PropertyName, expectPropertyName, StringComparison.Ordinal) == 0)
                {
                    eventCalled = true;
                }
            };

            Assert.That(eventCalled, Is.False);
            tabelModelMock.Raise(m => m.PropertyChanged += null, tabelModelMock, new PropertyChangedEventArgs(propertyNameToRaise));
            Assert.That(eventCalled, Is.True);

            exceptionHandleViewModelMock.AssertWasNotCalled(m => m.HandleException(Arg <Exception> .Is.Anything));
        }
コード例 #3
0
        public void TestAtPropertyChangedOnTabelModelEventHandlerKasterArgumentNullExceptionHvisEventArgsErNull()
        {
            var fixture = new Fixture();

            fixture.Customize <ITabelModelBase>(e => e.FromFactory(() => MockRepository.GenerateMock <ITabelModelBase>()));
            fixture.Customize <IExceptionHandlerViewModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IExceptionHandlerViewModel>()));

            var tabelModelMock = fixture.Create <ITabelModelBase>();
            var exceptionHandleViewModelMock = fixture.Create <IExceptionHandlerViewModel>();

            var tabelViewModel = new MyTabelViewModel(tabelModelMock, exceptionHandleViewModelMock);

            Assert.That(tabelViewModel, Is.Not.Null);

            var exception = Assert.Throws <ArgumentNullException>(() => tabelModelMock.Raise(m => m.PropertyChanged += null, fixture.Create <object>(), null));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("eventArgs"));
            Assert.That(exception.InnerException, Is.Null);

            exceptionHandleViewModelMock.AssertWasNotCalled(m => m.HandleException(Arg <Exception> .Is.Anything));
        }
コード例 #4
0
        public void TestAtPropertyChangedOnTabelModelEventHandlerKalderHandleExceptionOnExceptionHandlerViewModelHvisModelChangedKasterException(string propertyNameToRaise)
        {
            var fixture = new Fixture();

            fixture.Customize <ITabelModelBase>(e => e.FromFactory(() => MockRepository.GenerateMock <ITabelModelBase>()));
            fixture.Customize <IExceptionHandlerViewModel>(e => e.FromFactory(() => MockRepository.GenerateMock <IExceptionHandlerViewModel>()));

            var tabelModelMock = fixture.Create <ITabelModelBase>();
            var exceptionHandleViewModelMock = fixture.Create <IExceptionHandlerViewModel>();

            var tabelViewModel = new MyTabelViewModel(tabelModelMock, exceptionHandleViewModelMock)
            {
                ThrowExceptionInModelChanged = true
            };

            Assert.That(tabelViewModel, Is.Not.Null);
            Assert.That(tabelViewModel.ThrowExceptionInModelChanged, Is.True);

            Assert.That(tabelViewModel.IsModelChangedCalled, Is.False);
            tabelModelMock.Raise(m => m.PropertyChanged += null, tabelModelMock, new PropertyChangedEventArgs(propertyNameToRaise));
            Assert.That(tabelViewModel.IsModelChangedCalled, Is.True);

            exceptionHandleViewModelMock.AssertWasCalled(m => m.HandleException(Arg <IntranetGuiSystemException> .Is.TypeOf));
        }
コード例 #5
0
        public void TestAtConstructorInitiererTabelViewModelBase()
        {
            var fixture = new Fixture();

            var tabelModelMock = MockRepository.GenerateMock <ITabelModelBase>();

            tabelModelMock.Expect(m => m.Id)
            .Return(fixture.Create <string>())
            .Repeat.Any();
            tabelModelMock.Expect(m => m.Tekst)
            .Return(fixture.Create <string>())
            .Repeat.Any();

            var exceptionHandleViewModelMock = MockRepository.GenerateMock <IExceptionHandlerViewModel>();

            var tabelViewModel = new MyTabelViewModel(tabelModelMock, exceptionHandleViewModelMock);

            Assert.That(tabelViewModel, Is.Not.Null);
            Assert.That(tabelViewModel.Id, Is.Not.Null);
            Assert.That(tabelViewModel.Id, Is.Not.Empty);
            Assert.That(tabelViewModel.Id, Is.EqualTo(tabelModelMock.Id));
            Assert.That(tabelViewModel.Tekst, Is.Not.Null);
            Assert.That(tabelViewModel.Tekst, Is.Not.Empty);
            Assert.That(tabelViewModel.Tekst, Is.EqualTo(tabelModelMock.Tekst));
            Assert.That(tabelViewModel.DisplayName, Is.Not.Null);
            Assert.That(tabelViewModel.DisplayName, Is.Not.Empty);
            Assert.That(tabelViewModel.DisplayName, Is.EqualTo(tabelModelMock.Tekst));
            Assert.That(tabelViewModel.Model, Is.Not.Null);
            Assert.That(tabelViewModel.Model, Is.EqualTo(tabelModelMock));
            Assert.That(tabelViewModel.ExceptionHandler, Is.Not.Null);
            Assert.That(tabelViewModel.ExceptionHandler, Is.EqualTo(exceptionHandleViewModelMock));

            tabelModelMock.AssertWasCalled(m => m.Id);
            tabelModelMock.AssertWasCalled(m => m.Tekst);
            exceptionHandleViewModelMock.AssertWasNotCalled(m => m.HandleException(Arg <Exception> .Is.Anything));
        }