Skip to content

Commit 094e05b

Browse files
committed
all working
1 parent 6a87dc4 commit 094e05b

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/Api.Test/EndpointsTests/IntegrationTests/ProductControllerTest.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task GetByIdAsync_Returns_200(string culture, string version)
4949
{
5050
// Given
5151
var client = factory.CreateClient();
52-
var authResponse = await client.PostAsync(string.Format(SampleDataV1.readerLoginEndpoint, culture, version, Roles.Reader), null);
52+
var authResponse = await client.PostAsync(string.Format(SampleDataV1.readerLoginEndpoint, culture, version, Roles.Admin), null);
5353
var authDetails = JsonConvert.DeserializeObject<AuthenticateResponse>(await authResponse.Content.ReadAsStringAsync());
5454
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authDetails.Token);
5555
var addProductResponse = await client.PostAsJsonAsync(string.Format(SampleDataV1.productEndpoint, culture, version), SampleDataV1.Product);
@@ -92,13 +92,12 @@ public async Task PutAsync_Returns_204(string culture, string version)
9292
var putRequestPayload = new Product
9393
{
9494
Id = products.FirstOrDefault().Id,
95-
Name = products.FirstOrDefault().Name,
96-
DeliveryPrice = products.FirstOrDefault().DeliveryPrice,
97-
Price = products.FirstOrDefault().Price,
98-
Description = products.FirstOrDefault().Description
95+
Name = "Newname",
96+
DeliveryPrice = 11,
97+
Price = 22,
98+
Description = "newDescription"
9999
};
100-
101-
client = await SetupHttpClient(Roles.Reader, culture, version);
100+
client = await SetupHttpClient(Roles.Editor, culture, version);
102101

103102
// When
104103
var response = await client.PutAsJsonAsync(string.Format(SampleDataV1.productEndpoint, culture, version) + $"/{id}", putRequestPayload);
@@ -110,7 +109,7 @@ public async Task PutAsync_Returns_204(string culture, string version)
110109
private async Task<HttpClient> SetupHttpClient(string role, string culture, string version)
111110
{
112111
var client = factory.CreateClient();
113-
var authResponse = await client.PostAsync(string.Format(SampleDataV1.readerLoginEndpoint, culture, version, Roles.Reader), null);
112+
var authResponse = await client.PostAsync(string.Format(SampleDataV1.readerLoginEndpoint, culture, version, role), null);
114113
var authDetails = JsonConvert.DeserializeObject<AuthenticateResponse>(await authResponse.Content.ReadAsStringAsync());
115114
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authDetails.Token);
116115
return client;

src/Api/Endpoints/V1/Products/Update.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.AspNetCore.Authorization;
22
using Microsoft.AspNetCore.Http;
33
using Microsoft.AspNetCore.Mvc;
4-
using Microsoft.EntityFrameworkCore;
54
using System;
65
using System.Threading.Tasks;
76
using Xero.Demo.Api.Domain.Extension;
@@ -33,13 +32,11 @@ public async Task<IActionResult> PutAsync(Guid id, Product product, string cultu
3332

3433
if (savedProduct == default) return NotFound(string.Format(CustomException.NotFoundException, id));
3534

36-
var updatedProduct = _db.Products.Update(product);
37-
38-
var stateUpdated = updatedProduct.State == EntityState.Modified;
35+
_db.Products.Update(product);
3936

4037
var count = await _db.SaveChangesAsync();
4138

42-
return stateUpdated && count == 1 ? NoContent() : StatusCode(StatusCodes.Status500InternalServerError);
39+
return count == 1 ? NoContent() : StatusCode(StatusCodes.Status500InternalServerError);
4340
}
4441
}
4542
}

0 commit comments

Comments
 (0)