WIP commit
This commit is contained in:
parent
20ccdd07f1
commit
0187aec52a
2 changed files with 102 additions and 0 deletions
97
Website.Tests/Data/BlogRepositoryTests.cs
Normal file
97
Website.Tests/Data/BlogRepositoryTests.cs
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Dapper;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NSubstitute;
|
||||||
|
using NSubstitute.ExceptionExtensions;
|
||||||
|
using Website.Data;
|
||||||
|
using Website.Data.States;
|
||||||
|
using Website.Models;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Website.Tests.Data
|
||||||
|
{
|
||||||
|
public class BlogRepositoryTests
|
||||||
|
{
|
||||||
|
private class MockDbConnection : IDbConnection
|
||||||
|
{
|
||||||
|
public string ConnectionString { get; set; }
|
||||||
|
|
||||||
|
public int ConnectionTimeout => 0;
|
||||||
|
|
||||||
|
public string Database => string.Empty;
|
||||||
|
|
||||||
|
public ConnectionState State => ConnectionState.Open;
|
||||||
|
|
||||||
|
public IDbTransaction BeginTransaction()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDbTransaction BeginTransaction(IsolationLevel il)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeDatabase(string databaseName)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDbCommand CreateCommand()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Open()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetPostAsync_WithValidId_ReturnsBlogPost() {
|
||||||
|
var blogPostState = new BlogPostState
|
||||||
|
{
|
||||||
|
Post_Id = 1,
|
||||||
|
Post_Title = "title",
|
||||||
|
Post_Content = "content",
|
||||||
|
Post_Timestamp = new DateTime(),
|
||||||
|
Post_Deleted = false,
|
||||||
|
Post_Draft = "draft",
|
||||||
|
Post_Url = "url",
|
||||||
|
User_Id = 1
|
||||||
|
};
|
||||||
|
var connection = Substitute.For<IDbConnection>();
|
||||||
|
connection.QueryAsync(null, null, (Func<object[], BlogPostState>)null, null, null, false, null, null, null).ReturnsForAnyArgs(new[]{ blogPostState });
|
||||||
|
|
||||||
|
var provider = Substitute.For<IDatabaseProvider>();
|
||||||
|
provider.NewConnection().Returns(connection);
|
||||||
|
|
||||||
|
var repo = new BlogRepository(provider);
|
||||||
|
var post = repo.GetPostAsync(1);
|
||||||
|
var expected = new BlogPost
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Title = "title",
|
||||||
|
Content = "content",
|
||||||
|
Timestamp = new DateTime(),
|
||||||
|
Draft = "draft",
|
||||||
|
Url = "url",
|
||||||
|
UserId = 1
|
||||||
|
}; ;
|
||||||
|
post.Should().BeEquivalentTo(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
//public async Task GetPostAsync_WithInvalidId_ReturnsNull()
|
||||||
|
//public async Task GetPostAsync_WithDeletedPost_ReturnsNull()
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,11 @@ namespace Website.Models
|
||||||
UserId = state.User_Id;
|
UserId = state.User_Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlogPost()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public string Content { get; set; }
|
public string Content { get; set; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue