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;

            IStudentService service = testServer.Host.Services.GetService(typeof(IStudentService)) as IStudentService;
            var             model   = new ApiStudentServerRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", true, 1, "B", true, "B", "B", true, 1);
            CreateResponse <ApiStudentServerResponseModel> createdResponse = await service.Create(model);

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

            ActionResponse deleteResult = await client.StudentDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }
Esempio n. 2
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiStudentServerResponseModel response = await this.StudentService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
        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 ApiStudentServerModelMapper();
            ApplicationDbContext          context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IStudentService               service = testServer.Host.Services.GetService(typeof(IStudentService)) as IStudentService;
            ApiStudentServerResponseModel model   = await service.Get(1);

            ApiStudentClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", true, 1, "B", true, "B", "B", true, 1);

            UpdateResponse <ApiStudentClientResponseModel> updateResponse = await client.StudentUpdateAsync(model.Id, request);

            context.Entry(context.Set <Student>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Student>().ToList()[0].Birthday.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Student>().ToList()[0].Email.Should().Be("B");
            context.Set <Student>().ToList()[0].EmailRemindersEnabled.Should().Be(true);
            context.Set <Student>().ToList()[0].FamilyId.Should().Be(1);
            context.Set <Student>().ToList()[0].FirstName.Should().Be("B");
            context.Set <Student>().ToList()[0].IsAdult.Should().Be(true);
            context.Set <Student>().ToList()[0].LastName.Should().Be("B");
            context.Set <Student>().ToList()[0].Phone.Should().Be("B");
            context.Set <Student>().ToList()[0].SmsRemindersEnabled.Should().Be(true);
            context.Set <Student>().ToList()[0].UserId.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Birthday.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.Email.Should().Be("B");
            updateResponse.Record.EmailRemindersEnabled.Should().Be(true);
            updateResponse.Record.FamilyId.Should().Be(1);
            updateResponse.Record.FirstName.Should().Be("B");
            updateResponse.Record.IsAdult.Should().Be(true);
            updateResponse.Record.LastName.Should().Be("B");
            updateResponse.Record.Phone.Should().Be("B");
            updateResponse.Record.SmsRemindersEnabled.Should().Be(true);
            updateResponse.Record.UserId.Should().Be(1);
        }
Esempio n. 4
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IStudentService, IStudentRepository>();

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

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Esempio n. 5
0
		public void MapServerResponseToRequest()
		{
			var mapper = new ApiStudentServerModelMapper();
			var model = new ApiStudentServerResponseModel();
			model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", true, 1, "A", true, "A", "A", true, 1);
			ApiStudentServerRequestModel response = mapper.MapServerResponseToRequest(model);
			response.Should().NotBeNull();
			response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
			response.Email.Should().Be("A");
			response.EmailRemindersEnabled.Should().Be(true);
			response.FamilyId.Should().Be(1);
			response.FirstName.Should().Be("A");
			response.IsAdult.Should().Be(true);
			response.LastName.Should().Be("A");
			response.Phone.Should().Be("A");
			response.SmsRemindersEnabled.Should().Be(true);
			response.UserId.Should().Be(1);
		}
Esempio n. 6
0
        public async void Create_Errors()
        {
            StudentControllerMockFacade mock = new StudentControllerMockFacade();

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

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

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

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

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

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

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

                UpdateResponse <ApiStudentServerResponseModel> result = await this.StudentService.Update(id, model);

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