示例#1
0
        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 ApiEventStudentServerModelMapper();
            ApplicationDbContext context             = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IEventStudentService service             = testServer.Host.Services.GetService(typeof(IEventStudentService)) as IEventStudentService;
            ApiEventStudentServerResponseModel model = await service.Get(1);

            ApiEventStudentClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(1, 1);

            UpdateResponse <ApiEventStudentClientResponseModel> updateResponse = await client.EventStudentUpdateAsync(model.Id, request);

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

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.EventId.Should().Be(1);
            updateResponse.Record.StudentId.Should().Be(1);
        }
示例#2
0
        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;

            IEventStudentService service = testServer.Host.Services.GetService(typeof(IEventStudentService)) as IEventStudentService;
            var model = new ApiEventStudentServerRequestModel();

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

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

            ActionResponse deleteResult = await client.EventStudentDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }
示例#3
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiEventStudentServerModelMapper();
            var model  = new ApiEventStudentServerResponseModel();

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

            response.Should().NotBeNull();
            response.EventId.Should().Be(1);
            response.StudentId.Should().Be(1);
        }
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiEventStudentServerResponseModel response = await this.EventStudentService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IEventStudentService, IEventStudentRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <EventStudent>(null));
            var service = new EventStudentService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.EventStudentModelValidatorMock.Object,
                                                  mock.DALMapperMockFactory.DALEventStudentMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
示例#6
0
        public async void Create_Errors()
        {
            EventStudentControllerMockFacade mock = new EventStudentControllerMockFacade();

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

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiEventStudentServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiEventStudentServerResponseModel> >(mockResponse.Object));
            EventStudentController controller = new EventStudentController(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 ApiEventStudentServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiEventStudentServerRequestModel>()));
        }
示例#7
0
        public async void All_Exists()
        {
            EventStudentControllerMockFacade mock = new EventStudentControllerMockFacade();
            var record  = new ApiEventStudentServerResponseModel();
            var records = new List <ApiEventStudentServerResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            EventStudentController controller = new EventStudentController(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 <ApiEventStudentServerResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiEventStudentServerRequestModel> patch)
        {
            ApiEventStudentServerResponseModel record = await this.EventStudentService.Get(id);

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

                UpdateResponse <ApiEventStudentServerResponseModel> result = await this.EventStudentService.Update(id, model);

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