예제 #1
0
        public async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

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

            var createModel = new ApiEventRequestModel();

            createModel.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), 2m, 1, DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), "B", "B");
            CreateResponse <ApiEventResponseModel> createResult = await client.EventCreateAsync(createModel);

            createResult.Success.Should().BeTrue();

            ApiEventResponseModel getResponse = await client.EventGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.EventDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();

            ApiEventResponseModel verifyResponse = await client.EventGetAsync(2);

            verifyResponse.Should().BeNull();
        }
예제 #2
0
        private async Task <ApiEventResponseModel> CreateRecord()
        {
            var model = new ApiEventRequestModel();

            model.SetProperties("B", "B", 1, DateTime.Parse("1/1/1988 12:00:00 AM"), "B", DateTime.Parse("1/1/1988 12:00:00 AM"), "B", "B", DateTime.Parse("1/1/1988 12:00:00 AM"), "B");
            CreateResponse <ApiEventResponseModel> result = await this.Client.EventCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
예제 #3
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiEventRequestModel model)
 {
     this.ActualEndDateRules();
     this.ActualStartDateRules();
     this.BillAmountRules();
     this.EventStatusIdRules();
     this.ScheduledEndDateRules();
     this.ScheduledStartDateRules();
     this.StudentNoteRules();
     this.TeacherNoteRules();
     return(await this.ValidateAsync(model, id));
 }
예제 #4
0
        public virtual async Task <IActionResult> Create([FromBody] ApiEventRequestModel model)
        {
            CreateResponse <ApiEventResponseModel> result = await this.EventService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Events/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
예제 #5
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiEventRequestModel model)
 {
     this.Address1Rules();
     this.Address2Rules();
     this.CityIdRules();
     this.DateRules();
     this.DescriptionRules();
     this.EndDateRules();
     this.FacebookRules();
     this.NameRules();
     this.StartDateRules();
     this.WebsiteRules();
     return(await this.ValidateAsync(model, id));
 }
예제 #6
0
		public virtual async Task<CreateResponse<ApiEventResponseModel>> Create(
			ApiEventRequestModel model)
		{
			CreateResponse<ApiEventResponseModel> response = new CreateResponse<ApiEventResponseModel>(await this.eventModelValidator.ValidateCreateAsync(model));
			if (response.Success)
			{
				var bo = this.bolEventMapper.MapModelToBO(default(string), model);
				var record = await this.eventRepository.Create(this.dalEventMapper.MapBOToEF(bo));

				response.SetRecord(this.bolEventMapper.MapBOToModel(this.dalEventMapper.MapEFToBO(record)));
			}

			return response;
		}
 public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiEventRequestModel model)
 {
     this.AutoIdRules();
     this.CategoryRules();
     this.EnvironmentIdRules();
     this.JSONRules();
     this.MessageRules();
     this.OccurredRules();
     this.ProjectIdRules();
     this.RelatedDocumentIdsRules();
     this.TenantIdRules();
     this.UserIdRules();
     this.UsernameRules();
     return(await this.ValidateAsync(model, id));
 }
예제 #8
0
        private async Task <ApiEventRequestModel> PatchModel(int id, JsonPatchDocument <ApiEventRequestModel> patch)
        {
            var record = await this.EventService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiEventRequestModel request = this.EventModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
예제 #9
0
        public void MapModelToBO()
        {
            var mapper = new BOLEventMapper();
            ApiEventRequestModel model = new ApiEventRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), 1m, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A");
            BOEvent response = mapper.MapModelToBO(1, model);

            response.ActualEndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ActualStartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.BillAmount.Should().Be(1m);
            response.EventStatusId.Should().Be(1);
            response.ScheduledEndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ScheduledStartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.StudentNote.Should().Be("A");
            response.TeacherNote.Should().Be("A");
        }
예제 #10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IEventRepository>();
            var model = new ApiEventRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Event>())).Returns(Task.FromResult(new Event()));
            var service = new EventService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.EventModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLEventMapperMock,
                                           mock.DALMapperMockFactory.DALEventMapperMock);

            CreateResponse <ApiEventResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.EventModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiEventRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Event>()));
        }
예제 #11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IEventRepository>();
            var model = new ApiEventRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new EventService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.EventModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLEventMapperMock,
                                           mock.DALMapperMockFactory.DALEventMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.EventModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
예제 #12
0
        public void MapModelToBO()
        {
            var mapper = new BOLEventMapper();
            ApiEventRequestModel model = new ApiEventRequestModel();

            model.SetProperties("A", "A", 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A");
            BOEvent response = mapper.MapModelToBO(1, model);

            response.Address1.Should().Be("A");
            response.Address2.Should().Be("A");
            response.CityId.Should().Be(1);
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Description.Should().Be("A");
            response.EndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Facebook.Should().Be("A");
            response.Name.Should().Be("A");
            response.StartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Website.Should().Be("A");
        }
예제 #13
0
        public virtual BOEvent MapModelToBO(
            int id,
            ApiEventRequestModel model
            )
        {
            BOEvent boEvent = new BOEvent();

            boEvent.SetProperties(
                id,
                model.ActualEndDate,
                model.ActualStartDate,
                model.BillAmount,
                model.EventStatusId,
                model.ScheduledEndDate,
                model.ScheduledStartDate,
                model.StudentNote,
                model.TeacherNote);
            return(boEvent);
        }
예제 #14
0
        public void CreatePatch()
        {
            var mapper = new ApiEventModelMapper();
            var model  = new ApiEventRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), 1m, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A");

            JsonPatchDocument <ApiEventRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiEventRequestModel();

            patch.ApplyTo(response);
            response.ActualEndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ActualStartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.BillAmount.Should().Be(1m);
            response.EventStatusId.Should().Be(1);
            response.ScheduledEndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ScheduledStartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.StudentNote.Should().Be("A");
            response.TeacherNote.Should().Be("A");
        }
예제 #15
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiEventModelMapper();
            var model  = new ApiEventResponseModel();

            model.SetProperties("A", 1, "A", "A", "A", "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", "A");
            ApiEventRequestModel response = mapper.MapResponseToRequest(model);

            response.AutoId.Should().Be(1);
            response.Category.Should().Be("A");
            response.EnvironmentId.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Message.Should().Be("A");
            response.Occurred.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.ProjectId.Should().Be("A");
            response.RelatedDocumentIds.Should().Be("A");
            response.TenantId.Should().Be("A");
            response.UserId.Should().Be("A");
            response.Username.Should().Be("A");
        }
예제 #16
0
        public virtual async Task <UpdateResponse <ApiEventResponseModel> > Update(
            int id,
            ApiEventRequestModel model)
        {
            var validationResult = await this.eventModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolEventMapper.MapModelToBO(id, model);
                await this.eventRepository.Update(this.dalEventMapper.MapBOToEF(bo));

                var record = await this.eventRepository.Get(id);

                return(new UpdateResponse <ApiEventResponseModel>(this.bolEventMapper.MapBOToModel(this.dalEventMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiEventResponseModel>(validationResult));
            }
        }
예제 #17
0
        public virtual BOEvent MapModelToBO(
            int id,
            ApiEventRequestModel model
            )
        {
            BOEvent boEvent = new BOEvent();

            boEvent.SetProperties(
                id,
                model.Address1,
                model.Address2,
                model.CityId,
                model.Date,
                model.Description,
                model.EndDate,
                model.Facebook,
                model.Name,
                model.StartDate,
                model.Website);
            return(boEvent);
        }
예제 #18
0
        public virtual BOEvent MapModelToBO(
            string id,
            ApiEventRequestModel model
            )
        {
            BOEvent boEvent = new BOEvent();

            boEvent.SetProperties(
                id,
                model.AutoId,
                model.Category,
                model.EnvironmentId,
                model.JSON,
                model.Message,
                model.Occurred,
                model.ProjectId,
                model.RelatedDocumentIds,
                model.TenantId,
                model.UserId,
                model.Username);
            return(boEvent);
        }
예제 #19
0
        public void CreatePatch()
        {
            var mapper = new ApiEventModelMapper();
            var model  = new ApiEventRequestModel();

            model.SetProperties("A", "A", 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A");

            JsonPatchDocument <ApiEventRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiEventRequestModel();

            patch.ApplyTo(response);
            response.Address1.Should().Be("A");
            response.Address2.Should().Be("A");
            response.CityId.Should().Be(1);
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Description.Should().Be("A");
            response.EndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Facebook.Should().Be("A");
            response.Name.Should().Be("A");
            response.StartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Website.Should().Be("A");
        }
예제 #20
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiEventRequestModel model)
        {
            ApiEventRequestModel request = await this.PatchModel(id, this.EventModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiEventResponseModel> result = await this.EventService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
예제 #21
0
        public void CreatePatch()
        {
            var mapper = new ApiEventModelMapper();
            var model  = new ApiEventRequestModel();

            model.SetProperties(1, "A", "A", "A", "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", "A");

            JsonPatchDocument <ApiEventRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiEventRequestModel();

            patch.ApplyTo(response);
            response.AutoId.Should().Be(1);
            response.Category.Should().Be("A");
            response.EnvironmentId.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Message.Should().Be("A");
            response.Occurred.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.ProjectId.Should().Be("A");
            response.RelatedDocumentIds.Should().Be("A");
            response.TenantId.Should().Be("A");
            response.UserId.Should().Be("A");
            response.Username.Should().Be("A");
        }
예제 #22
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiEventRequestModel> patch)
        {
            ApiEventResponseModel record = await this.EventService.Get(id);

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

                UpdateResponse <ApiEventResponseModel> result = await this.EventService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
예제 #23
0
        public virtual async Task <UpdateResponse <ApiEventResponseModel> > EventUpdateAsync(int id, ApiEventRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Events/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiEventResponseModel> >(httpResponse.Content.ContentToString()));
        }