public virtual async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            var mapper = new ApiEventTeacherServerModelMapper();
            ApplicationDbContext context             = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IEventTeacherService service             = testServer.Host.Services.GetService(typeof(IEventTeacherService)) as IEventTeacherService;
            ApiEventTeacherServerResponseModel model = await service.Get(1);

            ApiEventTeacherClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(1, 1);

            UpdateResponse <ApiEventTeacherClientResponseModel> updateResponse = await client.EventTeacherUpdateAsync(model.Id, request);

            context.Entry(context.Set <EventTeacher>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <EventTeacher>().ToList()[0].EventId.Should().Be(1);
            context.Set <EventTeacher>().ToList()[0].TeacherId.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.EventId.Should().Be(1);
            updateResponse.Record.TeacherId.Should().Be(1);
        }
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IEventTeacherService service = testServer.Host.Services.GetService(typeof(IEventTeacherService)) as IEventTeacherService;
            var model = new ApiEventTeacherServerRequestModel();

            model.SetProperties(1, 1);
            CreateResponse <ApiEventTeacherServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.EventTeacherDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiEventTeacherServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
Exemplo n.º 3
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiEventTeacherServerModelMapper();
            var model  = new ApiEventTeacherServerResponseModel();

            model.SetProperties(1, 1, 1);
            ApiEventTeacherServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.EventId.Should().Be(1);
            response.TeacherId.Should().Be(1);
        }
Exemplo n.º 4
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiEventTeacherServerResponseModel response = await this.EventTeacherService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Exemplo n.º 5
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IEventTeacherService, IEventTeacherRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <EventTeacher>(null));
            var service = new EventTeacherService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.EventTeacherModelValidatorMock.Object,
                                                  mock.DALMapperMockFactory.DALEventTeacherMapperMock);

            ApiEventTeacherServerResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Exemplo n.º 6
0
        public async void Create_Errors()
        {
            EventTeacherControllerMockFacade mock = new EventTeacherControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiEventTeacherServerResponseModel> >(null as ApiEventTeacherServerResponseModel);
            var mockRecord   = new ApiEventTeacherServerResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiEventTeacherServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiEventTeacherServerResponseModel> >(mockResponse.Object));
            EventTeacherController controller = new EventTeacherController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiEventTeacherServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiEventTeacherServerRequestModel>()));
        }
Exemplo n.º 7
0
        public async void All_Exists()
        {
            EventTeacherControllerMockFacade mock = new EventTeacherControllerMockFacade();
            var record  = new ApiEventTeacherServerResponseModel();
            var records = new List <ApiEventTeacherServerResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            EventTeacherController controller = new EventTeacherController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.All(1000, 0, string.Empty);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiEventTeacherServerResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Exemplo n.º 8
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiEventTeacherServerRequestModel> patch)
        {
            ApiEventTeacherServerResponseModel record = await this.EventTeacherService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiEventTeacherServerRequestModel model = await this.PatchModel(id, patch) as ApiEventTeacherServerRequestModel;

                UpdateResponse <ApiEventTeacherServerResponseModel> result = await this.EventTeacherService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }