示例#1
0
        public async Task Should_Patch()
        {
            using var scope   = _fixture.Provider.CreateScope();
            using var context = scope.ServiceProvider.GetRequiredService <RatDbContext>();

            var projectTypes = await context.ProjectTypes.ToListAsync();

            var jsType     = projectTypes.First(x => x.Name == "js");
            var csharpType = projectTypes.First(x => x.Name == "csharp");

            var project = await context.Projects.AddAsync(new ProjectEntity { Name = "Patch", Type = jsType });

            await context.SaveChangesAsync();

            var model = new UpdateProjectRouteInput(project.Entity.Id, "New test", csharpType.Id);

            var response = await _fixture.Client.PatchAsync(
                $"/api/projects/{model.Id}",
                new StringContent(JsonSerializer.Serialize(model), Encoding.UTF8, "application/json"));

            var contentStream = await response.Content.ReadAsStreamAsync();

            var content = await JsonSerializer.DeserializeAsync <UpdateProjectRouteOutput>(contentStream, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal("New test", content.Name);
            Assert.Equal(csharpType.Id, content.TypeId);
        }
示例#2
0
        public async Task Should_Return_BadRequest_When_Name_Value_Is_Invalid(string name)
        {
            using var scope   = _fixture.Provider.CreateScope();
            using var context = scope.ServiceProvider.GetRequiredService <RatDbContext>();
            var projectType = await context.ProjectTypes.FirstAsync(x => x.Name == "js");

            var project = await context.Projects.AddAsync(new ProjectEntity { Name = "Patch", Type = projectType });

            await context.SaveChangesAsync();

            var model = new UpdateProjectRouteInput(project.Entity.Id, name, projectType.Id);

            var response = await _fixture.Client.PatchAsync(
                $"/api/projects/{model.Id}",
                new StringContent(JsonSerializer.Serialize(model), Encoding.UTF8, "application/json"));

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }