public void Should_Return_Success()
        {
            int result = 0;

            string sqlCommand = "SELECT IFNULL((SELECT 1 FROM information_schema.tables WHERE table_schema = 'mysqlcoretest' AND table_name = 'foo' LIMIT 1),0) as TableExist;";

            //Execute SQL Query
            using (var c = _connectionFactory.GetAsync().Result)
            {
                result = c.ExecuteScalarAsync <int>(sqlCommand.ToString()).Result;
            }

            Assert.IsTrue(result == 1);

            FooEntity f = new FooEntity()
            {
                id          = Guid.NewGuid(),
                Description = "Test",
                CreatedAt   = null
            };

            var rows = _repository.CreateAsync(f).Result;

            Assert.IsTrue(rows == 1);
        }
        public void Should_Return_DataEntity()
        {
            FooEntity entity = null;

            entity = Map.ToEntity <FooDTO, FooEntity>(_fooDTO);

            Assert.IsNotNull(entity);

            Assert.IsTrue(entity.id == _fooDTO.id && entity.Description == _fooDTO.Description);
        }
Example #3
0
        public void ReturnsResultsWithSpecText()
        {
            ISpecification <FooEntity> barTextSpecification = new FooWithBarSpec("bar text dummy");
            FooEntity fooCorrectText    = this.GivenAFooEntityWithBarText("bar text dummy");
            FooEntity fooNoCorrectText  = this.GivenAFooEntityWithBarText("other dummy");
            FooEntity fooNoCorrectText2 = this.GivenAFooEntityWithBarText("other dummy 2");

            FakeDbSet <FooEntity> fooDbSet = new FakeDbSet <FooEntity>()
            {
                fooCorrectText, fooNoCorrectText, fooNoCorrectText2
            };
            Mock <FakeDatabase>        database       = FakeDatabase.CreateMockOfFakeDatabase(fooDbSet);
            BaseRepository <FooEntity> baseRepository = this.GivenABaseRepositoryWithDatabase(database.Object);

            IEnumerable <FooEntity> results = baseRepository.GetAll(new Query <FooEntity>(barTextSpecification, null, null));

            Assert.AreEqual(1, results.Count());
            Assert.AreEqual(fooCorrectText, results.FirstOrDefault());
        }
Example #4
0
        private static void Run(IMapper mapper)
        {
            var fooEntity = new FooEntity {
                FirstName = "John", SecondName = "Foo"
            };
            var barEntity = new BarEntity {
                FirstName = "John", SecondName = "Bar"
            };

            var dto1 = mapper.Map <BarDto>(fooEntity);
            var dto2 = mapper.Map <BarDto>(barEntity);
            var dto3 = mapper.Map <FooDto>(fooEntity);

            var entity2 = mapper.Map <FooEntity>(dto2);
            var entity3 = mapper.Map <FooEntity>(dto3);

            Console.WriteLine($"From FooEntity {dto1.FullName}");
            Console.WriteLine($"From BarEntity {dto2.FullName}");
            Console.WriteLine($"From FooEntity {dto3.FullName}");

            Console.WriteLine($"From BarDto {entity2.FirstName} {entity2.SecondName}");
            Console.WriteLine($"From FooDto {entity3.FirstName} {entity3.SecondName}");
        }
Example #5
0
 FooAdapter(FooEntity entity)
 {
     this.entity = entity;
 }
 public async Task ShowGreeting(FooEntity entity)
 {
     await Console.Out.WriteLineAsync($"Id: {entity.Id.ToString()} Greeting: {entity.Greeting}");
 }
Example #7
0
        static void Main(string[] args)
        {
            //This goes in the startup
            var automapperConfig = new AutoMapperConfig().RegisterMappings();

            //Every single member has correlation with destination type.
            //It may not be the right one (since there are always exception cases),
            //but it at least tests that every property is moved from source type to destination.
            //will throw exception if not valid.
            automapperConfig.AssertConfigurationIsValid();

            //Get foo and bar entities  from database
            var fooEntity = new FooEntity()
            {
                EmployeeFName = "Foo", EmployeeLName = "Fooster"
            };
            var barEntity = new BarEntity()
            {
                PersonFirstName = "Bar", PersonLastName = "Cluster"
            };

            // auto map Entity to DTO
            var dtoFooModel = Mapper.Map(fooEntity, new FooDto(), typeof(FooEntity), typeof(DTO.FooDto));
            var dtoBarModel = Mapper.Map(barEntity, new BarDto(), typeof(BarEntity), typeof(DTO.BarDto));

            // Auto Map DTO Back to Entities
            var fooDTOFromUI = new FooDto()
            {
                EmployeeFName = "FooBackToEntity", EmployeeLName = "From Foo DTO"
            };
            var barDTOFromUI = new BarDto()
            {
                PersonFName = "BarBackToEntity", PersonLName = "FROM Bar DTO"
            };

            var entityFooModel = Mapper.Map(fooDTOFromUI, new FooEntity(), typeof(FooDto), typeof(FooEntity));
            var entityBarModel = Mapper.Map(barDTOFromUI, new BarEntity(), typeof(BarDto), typeof(BarEntity));

            //Get AddressEntity from database
            var addressEntity = new AddressEntity()
            {
                Street = "1751 Granger Cir",
                City   = "Castle Rock",
                State  = "CO",
                Zip    = "80109"
            };

            // auto map Entity to DTO
            var addressDto = new AddressDisplayOnlyDto();

            Mapper.Map(addressEntity, addressDto, typeof(AddressEntity), typeof(AddressDisplayOnlyDto));
            var p = addressDto.CompleteAddress;

            Console.WriteLine(p);
            Console.ReadKey();


            //Get Person and Address entity from database
            PersonEntity personEntity = new PersonEntity()
            {
                FirstName     = "Eric",
                LastName      = "Norton",
                PersonAddress = addressEntity
            };

            //Map person entity and personEntity.Address to personDto
            var dtoPersonModel = Mapper.Map(personEntity, new PersonDto(), typeof(PersonEntity), typeof(PersonDto));



            //Get Person DTO from UI
            PersonDto personDto = new PersonDto()
            {
                FName   = "Eric",
                LName   = "Nordin",
                Street  = "345 West Green St",
                City    = "Castle Rock",
                State   = "CO",
                ZipCode = "44565"
            };

            //Get Person DTO from UI and map back to person entity and address entity
            PersonEntity entityPersonModel = Mapper.Map(personDto, new PersonEntity(), typeof(PersonDto), typeof(PersonEntity)) as PersonEntity;
        }