Commit ca137027 authored by Steve Smith's avatar Steve Smith

All tests passing

parent e076d595
......@@ -8,7 +8,7 @@ namespace CleanArchitecture.Core
{
public static int PopulateDatabase(IRepository todoRepository)
{
if (todoRepository.List<ToDoItem>().Any()) return 0;
if (todoRepository.List<ToDoItem>().Count() >= 5) return 0;
todoRepository.Add(new ToDoItem
{
......
......@@ -13,9 +13,9 @@ namespace CleanArchitecture.Infrastructure.Data
{
private readonly IDomainEventDispatcher _dispatcher;
public AppDbContext(DbContextOptions options) : base(options)
{
}
//public AppDbContext(DbContextOptions options) : base(options)
//{
//}
public AppDbContext(DbContextOptions<AppDbContext> options, IDomainEventDispatcher dispatcher)
: base(options)
......
// <auto-generated />
using CleanArchitecture.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace CleanArchitecture.Infrastructure.Data.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20181203222230_InitialModel")]
partial class InitialModel
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.1.4-rtm-31024");
modelBuilder.Entity("CleanArchitecture.Core.Entities.ToDoItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Description");
b.Property<bool>("IsDone");
b.Property<string>("Title");
b.HasKey("Id");
b.ToTable("ToDoItems");
});
#pragma warning restore 612, 618
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace CleanArchitecture.Infrastructure.Data.Migrations
{
public partial class InitialModel : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ToDoItems",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Title = table.Column<string>(nullable: true),
Description = table.Column<string>(nullable: true),
IsDone = table.Column<bool>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ToDoItems", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ToDoItems");
}
}
}
// <auto-generated />
using CleanArchitecture.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace CleanArchitecture.Infrastructure.Data.Migrations
{
[DbContext(typeof(AppDbContext))]
partial class AppDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.1.4-rtm-31024");
modelBuilder.Entity("CleanArchitecture.Core.Entities.ToDoItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Description");
b.Property<bool>("IsDone");
b.Property<string>("Title");
b.HasKey("Id");
b.ToTable("ToDoItems");
});
#pragma warning restore 612, 618
}
}
}
......@@ -9,10 +9,26 @@ namespace CleanArchitecture.Web
{
public static class SeedData
{
public static readonly ToDoItem ToDoItem1 = new ToDoItem
{
Title = "Get Sample Working",
Description = "Try to get the sample to build."
};
public static readonly ToDoItem ToDoItem2 = new ToDoItem
{
Title = "Review Solution",
Description = "Review the different projects in the solution and how they relate to one another."
};
public static readonly ToDoItem ToDoItem3 = new ToDoItem
{
Title = "Run and Review Tests",
Description = "Make sure all the tests run and review what they are doing."
};
public static void Initialize(IServiceProvider serviceProvider)
{
using (var dbContext = new AppDbContext(
serviceProvider.GetRequiredService<DbContextOptions<AppDbContext>>()))
serviceProvider.GetRequiredService<DbContextOptions<AppDbContext>>(), null))
{
// Look for any TODO items.
if (dbContext.ToDoItems.Any())
......@@ -20,40 +36,23 @@ namespace CleanArchitecture.Web
return; // DB has been seeded
}
dbContext.ToDoItems.Add(new ToDoItem()
{
Title = "Test Item 1",
Description = "Test Description One"
});
dbContext.ToDoItems.Add(new ToDoItem()
{
Title = "Test Item 2",
Description = "Test Description Two"
});
dbContext.SaveChanges();
PopulateTestData(dbContext);
}
}
public static void PopulateTestData(AppDbContext dbContext)
{
var toDos = dbContext.ToDoItems;
foreach (var item in toDos)
foreach (var item in dbContext.ToDoItems)
{
dbContext.Remove(item);
}
dbContext.SaveChanges();
dbContext.ToDoItems.Add(new ToDoItem()
{
Title = "Test Item 1",
Description = "Test Description One"
});
dbContext.ToDoItems.Add(new ToDoItem()
{
Title = "Test Item 2",
Description = "Test Description Two"
});
dbContext.ToDoItems.Add(ToDoItem1);
dbContext.ToDoItems.Add(ToDoItem2);
dbContext.ToDoItems.Add(ToDoItem3);
dbContext.SaveChanges();
}
}
}
......@@ -26,9 +26,13 @@ namespace CleanArchitecture.Tests.Integration.Web.Api
var stringResponse = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<IEnumerable<ToDoItem>>(stringResponse).ToList();
Assert.Equal(2, result.Count());
Assert.Equal(1, result.Count(a => a.Title == "Test Item 1"));
Assert.Equal(1, result.Count(a => a.Title == "Test Item 2"));
Assert.Equal(3, result.Count());
Assert.Contains(result, i => i.Title == SeedData.ToDoItem1.Title);
Assert.Contains(result, i => i.Title == SeedData.ToDoItem2.Title);
Assert.Contains(result, i => i.Title == SeedData.ToDoItem3.Title);
//Assert.Equal(1, result.Count(a => a == SeedData.ToDoItem1));
//Assert.Equal(1, result.Count(a => a == SeedData.ToDoItem2));
//Assert.Equal(1, result.Count(a => a == SeedData.ToDoItem3));
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment