Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Todo.Tests/TestTodoListBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ public class TestTodoListBuilder
{
private readonly string title;
private readonly IdentityUser owner;
private readonly List<(string, Importance)> items = new List<(string, Importance)>();
private readonly List<(string, Importance, int)> items = new List<(string, Importance, int)>();

public TestTodoListBuilder(IdentityUser owner, string title)
{
this.title = title;
this.owner = owner;
}

public TestTodoListBuilder WithItem(string itemTitle, Importance importance)
public TestTodoListBuilder WithItem(string itemTitle, Importance importance, int rank)
{
items.Add((itemTitle, importance));
items.Add((itemTitle, importance, rank));
return this;
}

public TodoList Build()
{
var todoList = new TodoList(owner, title);
var todoItems = items.Select(itm => new TodoItem(todoList.TodoListId, owner.Id, itm.Item1, itm.Item2));
var todoItems = items.Select(itm => new TodoItem(todoList.TodoListId, owner.Id, itm.Item1, itm.Item2, itm.Item3));
todoItems.ToList().ForEach(tlItm =>
{
todoList.Items.Add(tlItm);
Expand Down
8 changes: 4 additions & 4 deletions Todo.Tests/Todo.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
Expand Down
2 changes: 1 addition & 1 deletion Todo.Tests/WhenTodoItemIsConvertedToEditFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class WhenTodoItemIsConvertedToEditFields
public WhenTodoItemIsConvertedToEditFields()
{
var todoList = new TestTodoListBuilder(new IdentityUser("alice@example.com"), "shopping")
.WithItem("bread", Importance.High)
.WithItem("bread", Importance.High, 5)
.Build()
;

Expand Down
2 changes: 1 addition & 1 deletion Todo/Controllers/TodoItemController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<IActionResult> Create(TodoItemCreateFields fields)
{
if (!ModelState.IsValid) { return View(fields); }

var item = new TodoItem(fields.TodoListId, fields.ResponsiblePartyId, fields.Title, fields.Importance);
var item = new TodoItem(fields.TodoListId, fields.ResponsiblePartyId, fields.Title, fields.Importance, fields.Rank);

await dbContext.AddAsync(item);
await dbContext.SaveChangesAsync();
Expand Down
2 changes: 2 additions & 0 deletions Todo/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<TodoList>(entity =>
{
entity.Property(e => e.TodoListId).UseIdentityColumn().HasAnnotation("SqlServer:Identity", "1, 1");
entity.Property(e => e.Title).IsRequired();
});

Expand All @@ -29,6 +30,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.HasOne(d => d.TodoList)
.WithMany(p => p.Items)
.HasForeignKey(d => d.TodoListId);
entity.Property(e => e.TodoItemId).UseIdentityColumn().HasAnnotation("SqlServer:Identity", "1, 1");
});
}
}
Expand Down
8 changes: 7 additions & 1 deletion Todo/Data/Entities/TodoItem.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
using Microsoft.AspNetCore.Identity;
using System.ComponentModel.DataAnnotations;

namespace Todo.Data.Entities {
public class TodoItem
{
[Key]
public int TodoItemId { get; set; }
public string Title { get; set; }
public string ResponsiblePartyId { get; set; }
public IdentityUser ResponsibleParty { get; set; }
public bool IsDone { get; set; }

[MaxLength(5)]
public int Rank { get; set; }
public Importance Importance { get; set; }

public int TodoListId { get; set; }
public TodoList TodoList { get; set; }

protected TodoItem() { }

public TodoItem(int todoListId, string responsiblePartyId, string title, Importance importance)
public TodoItem(int todoListId, string responsiblePartyId, string title, Importance importance, int rank)
{
TodoListId = todoListId;
ResponsiblePartyId = responsiblePartyId;
Title = title;
Importance = importance;
this.Rank = rank;
}
}
}
2 changes: 2 additions & 0 deletions Todo/Data/Entities/TodoList.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Identity;

namespace Todo.Data.Entities
{
public class TodoList
{
[Key]
public int TodoListId { get; set; }
public string Title { get; set; }
public IdentityUser Owner { get; set; }
Expand Down
236 changes: 0 additions & 236 deletions Todo/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs

This file was deleted.

Loading