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

            var systemDataRepositoryMock = MockRepository.GenerateMock <ISystemDataRepository>();

            systemDataRepositoryMock.Stub(m => m.Get <ITranslationInfo>(Arg <Guid> .Is.Anything))
            .Return(DomainObjectMockBuilder.BuildTranslationInfoMock())
            .Repeat.Any();
            systemDataRepositoryMock.Stub(m => m.StaticTextGetByStaticTextType(Arg <StaticTextType> .Is.Anything))
            .Return(DomainObjectMockBuilder.BuildStaticTextMock())
            .Repeat.Any();

            var foodWasteObjectMapperMock = MockRepository.GenerateMock <IFoodWasteObjectMapper>();

            foodWasteObjectMapperMock.Stub(m => m.Map <IStaticText, StaticTextView>(Arg <IStaticText> .Is.Anything, Arg <CultureInfo> .Is.Anything))
            .Return(fixture.Create <StaticTextView>())
            .Repeat.Any();

            foreach (var staticTextTypeToTest in Enum.GetValues(typeof(StaticTextType)).Cast <StaticTextType>())
            {
                var staticTextGetQueryHandlerBase = new MyStaticTextGetQueryHandler(staticTextTypeToTest, systemDataRepositoryMock, foodWasteObjectMapperMock);
                Assert.That(staticTextGetQueryHandlerBase, Is.Not.Null);

                var staticTextGetQuery = fixture.Build <MyStaticTextGetQuery>()
                                         .With(m => m.TranslationInfoIdentifier, Guid.NewGuid())
                                         .Create();

                staticTextGetQueryHandlerBase.Query(staticTextGetQuery);

                // ReSharper disable AccessToForEachVariableInClosure
                systemDataRepositoryMock.AssertWasCalled(m => m.StaticTextGetByStaticTextType(Arg <StaticTextType> .Is.Equal(staticTextTypeToTest)));
                // ReSharper restore AccessToForEachVariableInClosure
            }
        }
コード例 #2
0
        public void TestThatQueryReturnsViewFromMapOnFoodWasteObjectMapper()
        {
            var fixture = new Fixture();

            var systemDataRepositoryMock = MockRepository.GenerateMock <ISystemDataRepository>();

            systemDataRepositoryMock.Stub(m => m.Get <ITranslationInfo>(Arg <Guid> .Is.Anything))
            .Return(DomainObjectMockBuilder.BuildTranslationInfoMock())
            .Repeat.Any();
            systemDataRepositoryMock.Stub(m => m.StaticTextGetByStaticTextType(Arg <StaticTextType> .Is.Anything))
            .Return(DomainObjectMockBuilder.BuildStaticTextMock())
            .Repeat.Any();

            var staticTextView            = fixture.Create <StaticTextView>();
            var foodWasteObjectMapperMock = MockRepository.GenerateMock <IFoodWasteObjectMapper>();

            foodWasteObjectMapperMock.Stub(m => m.Map <IStaticText, StaticTextView>(Arg <IStaticText> .Is.Anything, Arg <CultureInfo> .Is.Anything))
            .Return(staticTextView)
            .Repeat.Any();

            var staticTextGetQueryHandlerBase = new MyStaticTextGetQueryHandler(fixture.Create <StaticTextType>(), systemDataRepositoryMock, foodWasteObjectMapperMock);

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

            var staticTextGetQuery = fixture.Build <MyStaticTextGetQuery>()
                                     .With(m => m.TranslationInfoIdentifier, Guid.NewGuid())
                                     .Create();

            var result = staticTextGetQueryHandlerBase.Query(staticTextGetQuery);

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.EqualTo(staticTextView));
        }
コード例 #3
0
        public void TestThatQueryThrowsArgumentNullExceptionIfDataProviderCollectionGetQueryIsNull()
        {
            var fixture = new Fixture();
            var systemDataRepositoryMock  = MockRepository.GenerateMock <ISystemDataRepository>();
            var foodWasteObjectMapperMock = MockRepository.GenerateMock <IFoodWasteObjectMapper>();

            var staticTextGetQueryHandlerBase = new MyStaticTextGetQueryHandler(fixture.Create <StaticTextType>(), systemDataRepositoryMock, foodWasteObjectMapperMock);

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

            var exception = Assert.Throws <ArgumentNullException>(() => staticTextGetQueryHandlerBase.Query(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("query"));
            Assert.That(exception.InnerException, Is.Null);
        }