public static Customer ToEntity(this CustomerEditCreateRequest dto)
 {
     return(new Customer
     {
         Id = dto.Id,
         Name = dto.Name
     });
 }
Beispiel #2
0
        protected override async Task <CustomerDetailsCreateResponse> EditItemAsync(CustomerEditCreateRequest request)
        {
            var entity = request.ToEntity();

            await repository.UpdateAsync(entity);

            return(entity.ToDto());
        }
Beispiel #3
0
        protected override async Task <CustomerDetailsCreateResponse> AddItemAsync(CustomerEditCreateRequest request)
        {
            var entity = request.ToEntity();

            var newEntity = await repository.AddAsync(entity);

            return(newEntity.ToDto());
        }
Beispiel #4
0
 public override async Task <IHttpActionResult> Edit([FromBody] CustomerEditCreateRequest request)
 {
     return(await DoEditAsync(request));
 }
Beispiel #5
0
        public async Task CustomerController_ShouldPerformCrudOperations()
        {
            const string NAME         = "IntegrationTest Name";
            const string NAME_UPDATED = "IntegrationTest Name Updated";
            const int    DEFAULT_ID   = default;

            //ensure no remnants of failed tests
            await EnsureNoCrudRemnants(NAME);
            await EnsureNoCrudRemnants(NAME_UPDATED);

            //CREATE
            var createCustomerRequest = new CustomerEditCreateRequest {
                Name = NAME
            };
            var controller       = classFactory.GetExport <CustomerController>();
            var sutDetailsCreate = await controller.Create(createCustomerRequest);

            var insertedItem   = sutDetailsCreate.GetCreatedValue <CustomerDetailsCreateResponse>();
            var insertedItemId = insertedItem.Id; //store id for future use

            insertedItemId.ShouldNotBe(DEFAULT_ID);

            //DETAILS
            sutDetailsCreate = await controller.Details(insertedItemId);

            var detailedItem = sutDetailsCreate.GetOkValue <CustomerDetailsCreateResponse>();

            detailedItem.ShouldNotBeNull();
            detailedItem.Name.ShouldBe(NAME);
            detailedItem.Id.ShouldBe(insertedItemId);

            //EDIT
            var updateCustomerRequest = new CustomerEditCreateRequest
            {
                Id   = insertedItemId,
                Name = NAME_UPDATED,
            };

            sutDetailsCreate = await controller.Edit(updateCustomerRequest);

            var okItem = sutDetailsCreate.GetOkResult();

            okItem.ShouldNotBeNull();

            //SUGGESTIONS
            var sutSuggestions = await controller.Suggestions(string.Empty);

            var suggestions = sutSuggestions.GetOkValue <List <string> >();

            suggestions.ShouldNotBeNull();
            suggestions.Count.ShouldBeGreaterThan(0);

            //INDEX
            var sutIndex = await controller.Index(null);

            var pagedRows = sutIndex.GetOkValue <CustomerIndexResponse>();

            pagedRows.ShouldNotBeNull();
            pagedRows.Items.Count.ShouldBeGreaterThan(0);

            //DELETE
            var sutDelete = await controller.Delete(insertedItemId, "Integration Test");

            okItem = sutDelete.GetOkResult();
            okItem.ShouldNotBeNull();

            //Retest after Delete
            // Validate the the row has been soft deleted
            sutDetailsCreate = await controller.Details(insertedItemId);

            var deletedItem = sutDetailsCreate.Get404Result();

            deletedItem.ShouldNotBeNull();

            await EnsureNoCrudRemnants(NAME);
            await EnsureNoCrudRemnants(NAME_UPDATED);
        }