예제 #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);
            }
        }
예제 #2
0
        public void Initialize()
        {
            DbContextHelpers contextHelpers = new DbContextHelpers();

            db           = contextHelpers.getDbContext();
            myProfileCon = new MyProfileController(db.Object)
            {
                ControllerContext = MockContext.AuthenticationContext("jjones")
            };
        }
예제 #3
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);
            }
        }
예제 #4
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);
            }
        }