Exemplo n.º 1
0
        public void PostOwner()
        {
            using (MyProfileDbContext context = new MyProfileDbContext(_dbContextOptions))
            {
                IMapper mapper = CreateMapperConfig();

                MyProfileController myProfileController = new MyProfileController(mapper, new OwnerRepository(context), new AddressRepository(context), new ContactRepository(context), new ExperienceRepository(context));

                OwnerDto owner = new OwnerDto()
                {
                    DateBirth = DateTime.Now,
                    FirstName = $"Post",
                    LastName  = $"Test"
                };

                IActionResult        result = myProfileController.PostOwner(owner);
                CreatedAtRouteResult createdAtRouteResult = result as CreatedAtRouteResult;
                OwnerDto             ownerDtoResult       = createdAtRouteResult.Value as OwnerDto;

                Assert.Equal("GetOwner", createdAtRouteResult.RouteName);
                Assert.Equal(201, createdAtRouteResult.StatusCode);
                Assert.NotNull(ownerDtoResult);
                Assert.Equal(1, ownerDtoResult.ID);
            }
        }
Exemplo n.º 2
0
        public async void PutOwner()
        {
            using (MyProfileDbContext context = new MyProfileDbContext(_dbContextOptions))
            {
                IMapper mapper = CreateMapperConfig();

                MyProfileController myProfileController = new MyProfileController(mapper, new OwnerRepository(context), new AddressRepository(context), new ContactRepository(context), new ExperienceRepository(context));

                for (int i = 0; i < 10; ++i)
                {
                    OwnerDto owner = new OwnerDto()
                    {
                        DateBirth = DateTime.Now,
                        FirstName = $"Test{i}",
                        LastName  = $"{i}Test"
                    };

                    myProfileController.PostOwner(owner);
                }
            }

            using (MyProfileDbContext context = new MyProfileDbContext(_dbContextOptions))
            {
                IMapper mapper = CreateMapperConfig();

                MyProfileController myProfileController = new MyProfileController(mapper, new OwnerRepository(context), new AddressRepository(context), new ContactRepository(context), new ExperienceRepository(context));

                IActionResult getResult = await myProfileController.GetOwner(3);

                OkObjectResult okResult = getResult as OkObjectResult;
                OwnerDto       ownerDto = okResult.Value as OwnerDto;
                ownerDto.FirstName += "Updated";

                IActionResult result = await myProfileController.PutOwner(3, ownerDto);

                NoContentResult noContentResult = result as NoContentResult;

                IActionResult updatedResult = await myProfileController.GetOwner(3);

                okResult = updatedResult as OkObjectResult;
                OwnerDto ownerDtoUpdated = okResult.Value as OwnerDto;

                Assert.NotNull(noContentResult);
                Assert.Equal(204, noContentResult.StatusCode);
                Assert.Equal("Test2Updated", ownerDtoUpdated.FirstName);
            }
        }
Exemplo n.º 3
0
        public async void DeleteOwner()
        {
            using (MyProfileDbContext context = new MyProfileDbContext(_dbContextOptions))
            {
                IMapper mapper = CreateMapperConfig();

                MyProfileController myProfileController = new MyProfileController(mapper, new OwnerRepository(context), new AddressRepository(context), new ContactRepository(context), new ExperienceRepository(context));

                for (int i = 0; i < 10; ++i)
                {
                    OwnerDto owner = new OwnerDto()
                    {
                        DateBirth = DateTime.Now,
                        FirstName = $"Test{i}",
                        LastName  = $"{i}Test"
                    };

                    myProfileController.PostOwner(owner);
                }
            }

            using (MyProfileDbContext context = new MyProfileDbContext(_dbContextOptions))
            {
                IMapper mapper = CreateMapperConfig();

                MyProfileController myProfileController = new MyProfileController(mapper, new OwnerRepository(context), new AddressRepository(context), new ContactRepository(context), new ExperienceRepository(context));

                IActionResult result = await myProfileController.DeleteOwner(3);

                NoContentResult noContentResult = result as NoContentResult;

                IActionResult getResult = await myProfileController.GetOwners();

                OkObjectResult  okResult = getResult as OkObjectResult;
                List <OwnerDto> owners   = okResult.Value as List <OwnerDto>;

                Assert.NotNull(noContentResult);
                Assert.Equal(204, noContentResult.StatusCode);
                Assert.Equal(9, owners.Count);
            }
        }
Exemplo n.º 4
0
 protected RepositoryBase(MyProfileDbContext context)
 {
     DbContext = context;
 }
Exemplo n.º 5
0
 public AddressRepository(MyProfileDbContext context) : base(context)
 {
 }
Exemplo n.º 6
0
 public ContactRepository(MyProfileDbContext context) : base(context)
 {
 }
Exemplo n.º 7
0
 public OwnerRepository(MyProfileDbContext context) : base(context)
 {
 }
Exemplo n.º 8
0
 public ExperienceRepository(MyProfileDbContext context) : base(context)
 {
 }