コード例 #1
0
        public void MapNullInstance_Test()
        {
            // arrange
            StubDb dto1 = null;
            var    sut  = new AutoMapperEntityMapper(StubEntityMapperConfiguration.Create());

            // act
            var result = sut.Map <StubPerson>(dto1);

            // assert
            result.ShouldBeNull();
        }
コード例 #2
0
        public void MapInstance_Test()
        {
            // arrange
            var dto1 = new StubDb {
                Identifier = "111"
            };
            var sut = new AutoMapperEntityMapper(StubEntityMapperConfiguration.Create());

            // act
            var result = sut.Map <StubPerson>(dto1);

            // assert
            result.Id.ShouldBe("111");
        }
コード例 #3
0
        public void MapPropertySpecification_Test()
        {
            // arrange
            var dto1 = new StubDb {
                FullName = "John Doe"
            };
            var dto2 = new StubDb {
                FullName = "John Does"
            };
            var specification = new StubHasNameSpecification("John", "Doe");
            var sut           = new AutoMapperEntityMapper(StubEntityMapperConfiguration.Create());

            // act
            var result = sut.MapSpecification <StubPerson, StubDb>(specification).Compile();

            // assert
            result(dto1).ShouldBeTrue();
            result(dto2).ShouldBeFalse();
        }
コード例 #4
0
        public void MapIdSpecification_Test()
        {
            // arrange
            var dto1 = new StubDb {
                Identifier = "111"
            };
            var dto2 = new StubDb {
                Identifier = "333"
            };
            var specification = new StubHasIdSpecification("111");
            var sut           = new AutoMapperEntityMapper(StubEntityMapperConfiguration.Create());

            // act
            var result = sut.MapSpecification <StubPerson, StubDb>(specification).Compile();

            // assert
            result(dto1).ShouldBeTrue();
            result(dto2).ShouldBeFalse();
        }
コード例 #5
0
        public async Task FindAllTenantEntities_Test() // TODO: move to own test class + mocks
        {
            // arrange
            var sut = new RepositorySpecificationDecorator <StubPerson>(
                new Specification <StubPerson>(t => t.TenantId == this.tenantId),
                new InMemoryRepository <StubPerson, StubDb>(o => o
                                                            .Mediator(Substitute.For <IMediator>())
                                                            .Context(new InMemoryContext <StubPerson>(this.entities))
                                                            .Mapper(new AutoMapperEntityMapper(StubEntityMapperConfiguration.Create())),
                                                            e => e.Identifier));

            // act
            var result = await sut.FindAllAsync().AnyContext();

            // assert
            Assert.False(result.IsNullOrEmpty());
            Assert.Equal(21, result.Count());
            Assert.NotNull(result.FirstOrDefault(e => e.Id == "Id99"));
        }
コード例 #6
0
        public async Task FindAllEntities_Test()
        {
            // arrange
            var sut = new InMemoryRepository <StubPerson, StubDb>(o => o
                                                                  .Mediator(Substitute.For <IMediator>())
                                                                  .Context(new InMemoryContext <StubPerson>(this.entities))
                                                                  .Mapper(new AutoMapperEntityMapper(StubEntityMapperConfiguration.Create())),
                                                                  e => e.Identifier);

            // act
            var result = await sut.FindAllAsync().AnyContext();

            // assert
            Assert.NotNull(result);
            Assert.True(result.All(e => !e.Id.IsNullOrEmpty() && !e.FirstName.IsNullOrEmpty() && !e.LastName.IsNullOrEmpty()));
            Assert.NotNull(result.FirstOrDefault(e => e.FirstName == "John" && e.LastName == "Doe"));
        }
コード例 #7
0
        public async Task FindOneTenantEntity_Test()
        {
            // arrange
            var sut = new RepositorySpecificationDecorator <StubPerson>(
                new Specification <StubPerson>(t => t.TenantId == this.tenantId),
                new InMemoryRepository <StubPerson, StubDb>(o => o
                                                            .Mediator(Substitute.For <IMediator>())
                                                            .Context(new InMemoryContext <StubPerson>(this.entities))
                                                            .Mapper(new AutoMapperEntityMapper(StubEntityMapperConfiguration.Create())),
                                                            e => e.Identifier));

            // act
            var result = await sut.FindOneAsync("Id99").AnyContext();

            // assert
            Assert.NotNull(result);
            Assert.True(result.Id == "Id99");
        }
コード例 #8
0
        public async Task FindMappedEntitiesWithSpecification_Test()
        {
            // arrange
            var sut = new InMemoryRepository <StubPerson, StubDb>(o => o
                                                                  .Mediator(Substitute.For <IMediator>())
                                                                  .Context(new InMemoryContext <StubPerson>(this.entities))
                                                                  .Mapper(new AutoMapperEntityMapper(StubEntityMapperConfiguration.Create())),
                                                                  e => e.Identifier);

            // act
            var result = await sut.FindAllAsync(
                new StubHasNameSpecification("John", "Doe"),
                new FindOptions <StubPerson>(orderExpression : e => e.Country)).AnyContext(); // domain layer

            //var result = await sut.FindAllAsync(
            //    new StubHasIdSpecification("Id99")).AnyContext(); // domain layer

            // assert
            Assert.NotNull(result);
            Assert.Single(result);
            Assert.NotNull(result.FirstOrDefault()?.Id);
            Assert.NotNull(result.FirstOrDefault(e => !e.FirstName.IsNullOrEmpty() && !e.LastName.IsNullOrEmpty()));
        }