Skip to content

Commit

Permalink
Merge pull request #82 from thenewboston-developers/develop
Browse files Browse the repository at this point in the history
[Release] Add app layer
  • Loading branch information
Mirch committed Jan 4, 2021
2 parents 1eda0ed + 0aee182 commit ca44ade
Show file tree
Hide file tree
Showing 89 changed files with 2,358 additions and 196 deletions.
28 changes: 23 additions & 5 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,25 @@ For projects that support adding a Nuget reference you may paste the following
## SDK References
1. Bank
* AccountsService
* BankConfirmationBlockService
* BlocksService
* ConfigService
* ConnectedBankService
* TransactionService
* InvalidBlocksService
* TransactionsService
* UpgradeNoticeService
* ValidatorService
* BankConfirmationBlockService
2. Common
*
3. Validator
* AccountsService
* BankBlockService
* ConfigService
* ConnectedBankService
* PrimaryValidatorUpdatedService
* TransactionService
* UpgradeRequestService
* ValidatorService
* ValidatorConfirmationBlockService

Expand All @@ -64,14 +71,20 @@ Description
Thenewboston.Bank.Api
Thenewboston.Bank.Models
## AccountsService
## AccountsService
## BankConfirmationBLockService
## BlocksService
## ConfigService
## ConfirmationService
## ConnectedBankService
## ConnectionRequestService
## InvalidBlocksService
## TransactionService
## UpgradeNoticeService
## ValidatorService
## BankConfirmationBlockService
## Bank Exceptions (BNK)
|Exception|Class|Thrown From|Description |

|Exception|Class|Thrown From|Description|
|--|--|--|--|
|BNK001|AccountsService|SampleMethod()|Sample Description|
|BNK002|ConfigService|SampleMethod()|Sample Description|
Expand All @@ -96,9 +109,14 @@ Description
Thenewboston.Validator.Api
Thenewboston.Validator.Models
## AccountsService
## BankBlockService
## ConfigService
## ConfirmationService
## ConnectedBankService
## ConnectionRequestService
## PrimaryValidatorUpdatedService
## TransactionService
## UpgradeRequestService
## ValidatorService
## ValidatorConfirmationBlockService
## Validator Exceptions (VLD)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
This is a .NET Core SDK for **thenewboston**, which will be available cross-platoform. The library itself will solely contain the domain and data layers of **thenewboston**. The presentation layer will be the responsibility of the host application.

## Status
![SDK CI pipeline](https://github.com/thenewboston-developers/dotnetcore-sdk/workflows/SDK%20CI%20pipeline/badge.svg)
![SDK CI pipeline](https://github.com/thenewboston-developers/dotnetcore-sdk/workflows/SDK%20CI%20pipeline/badge.svg)
![Create and Publish package](https://github.com/thenewboston-developers/dotnetcore-sdk/workflows/Create%20and%20Publish%20package/badge.svg?branch=main)


## How to get started
Expand Down
52 changes: 28 additions & 24 deletions src/Thenewboston.Tests/Bank/Api/AccountsServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Xunit;
using System.Linq;
using Thenewboston.Bank.Api.Models;
using Thenewboston.Common.Api.Models;

namespace Thenewboston.Tests.Bank.Api
{
Expand All @@ -25,8 +26,8 @@ public async void ListOfAccountsIsReturned()

var accounts = await service.GetAccountsAsync();

Assert.Equal(2, accounts.Count());
Assert.Equal("9eca00a5-d925-454c-a8d6-ecbb26ec2f76", accounts.ElementAt(0).Id);
Assert.Equal(2, accounts.Count);
Assert.Equal("9eca00a5-d925-454c-a8d6-ecbb26ec2f76", accounts.Results.ElementAt(0).Id);
}
}

Expand All @@ -49,35 +50,37 @@ public static AccountsService BuildAccountsServiceMock()
{
var requestSender = new Mock<IHttpRequestSender>();

var listResult = new List<BankAccount>
{
new BankAccount
{
Id = "9eca00a5-d925-454c-a8d6-ecbb26ec2f76",
AccountNumber = "4d2ec91f37bc553bc538e91195669b666e26b2ea3e4e31507e38102a758d4f86",
Created = DateTime.Now.AddDays(-3),
Modified = DateTime.Now,
Trust = "99.73"
},
new BankAccount
{
Id = "ae4d43b0-5c34-4e56-8266-0e3531268815",
AccountNumber = "a29baa6ba36f6db707f8f8dacfa82d5e8a28fa616e8cc96cf6d7790f551d79f2",
Created = DateTime.Now.AddDays(-3),
Modified = DateTime.Now,
Trust = "94.61"
var listResult = new PaginatedResponseModel<BankAccount>() {
Count = 2,
Next = string.Empty,
Previous = string.Empty,
Results = new List<BankAccount>() {
new BankAccount {
Id = "9eca00a5-d925-454c-a8d6-ecbb26ec2f76",
AccountNumber = "4d2ec91f37bc553bc538e91195669b666e26b2ea3e4e31507e38102a758d4f86",
Created = DateTime.Now.AddDays(-3),
Modified = DateTime.Now,
Trust = "99.73"
},
new BankAccount {
Id = "ae4d43b0-5c34-4e56-8266-0e3531268815",
AccountNumber = "a29baa6ba36f6db707f8f8dacfa82d5e8a28fa616e8cc96cf6d7790f551d79f2",
Created = DateTime.Now.AddDays(-3),
Modified = DateTime.Now,
Trust = "94.61"
}
}
};

var getAllResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
getAllResponse.Content = new StringContent(JsonConvert.SerializeObject(listResult), Encoding.UTF8, "application/json");
getAllResponse.Content =
new StringContent(JsonConvert.SerializeObject(listResult), Encoding.UTF8, "application/json");

requestSender
.Setup(x => x.GetAsync(It.IsAny<string>()))
.Returns(Task.FromResult(getAllResponse));

var updateResult = new BankAccount
{
var updateResult = new BankAccount {
Id = "64426fc5-b3ac-42fb-b75b-d5ccfcdc6872",
AccountNumber = "a29baa6ba36f6db707f8f8dacfa82d5e8a28fa616e8cc96cf6d7790f551d79f2",
Created = DateTime.Now.AddDays(-3),
Expand All @@ -86,7 +89,8 @@ public static AccountsService BuildAccountsServiceMock()
};

var updateResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
updateResponse.Content = new StringContent(JsonConvert.SerializeObject(updateResult), Encoding.UTF8, "application/json");
updateResponse.Content = new StringContent(JsonConvert.SerializeObject(updateResult), Encoding.UTF8,
"application/json");

requestSender
.Setup(x => x.PatchAsync(It.IsAny<string>(), It.IsAny<StringContent>()))
Expand All @@ -96,4 +100,4 @@ public static AccountsService BuildAccountsServiceMock()
return bankService;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Moq;
using Newtonsoft.Json;
using Thenewboston.Bank.Api;
using Thenewboston.Bank.Api.Models;
using Thenewboston.Bank.Models;
using Thenewboston.Common.Api.Models;
using Thenewboston.Common.Http;
Expand All @@ -23,17 +24,17 @@ public class BankConfirmationBlockServiceTests

#region Test Models

private PaginatedResponseModel CreateMockBankConfirmationBlock()
private PaginatedResponseModel<BankConfirmationBlock> CreateMockBankConfirmationBlock()
{
return new PaginatedResponseModel()
return new PaginatedResponseModel<BankConfirmationBlock>()
{
Count = 1,
Next = string.Empty,
Previous = string.Empty,
Results =
new List<BankConfirmationBlockResponse>()
new List<BankConfirmationBlock>()
{
new BankConfirmationBlockResponse
new BankConfirmationBlock
{
Id = "e7c5c2e0-8ed1-4eb3-abd8-97fa2e5ca8db",
CreatedDate = DateTime.Parse("2020-10-08T02:18:07.908635Z"),
Expand Down Expand Up @@ -143,10 +144,10 @@ private IBankConfirmationBlockService BuildConfirmationBlockPostMock()
#region Tests

[Fact]
public async void BankConfiramtionBlockReturnedAsync()
public async void BankConfirmationBlockReturnedAsync()
{
var service = BuildConfirmationBlockGetMock();
var returnedBankConfirmationBlock = await service.GetAllBankConfiramtionBlocksAsync();
var returnedBankConfirmationBlock = await service.GetAllBankConfiramtionBlocksAsync(0, 10);
var expectedResult = JsonConvert.SerializeObject(CreateMockBankConfirmationBlock());
var actualResult = JsonConvert.SerializeObject(returnedBankConfirmationBlock);
Assert.Equal(expectedResult, actualResult);
Expand Down
121 changes: 121 additions & 0 deletions src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using Moq;
using Newtonsoft.Json;
using Thenewboston.Bank.Api;
using Thenewboston.Bank.Models;
using Thenewboston.Common.Api.Models;
using Thenewboston.Common.Http;
using Thenewboston.Common.Models;
using Xunit;
using Block = Thenewboston.Common.Models.Block;
using BlockMessage = Thenewboston.Common.Models.BlockMessage;

namespace Thenewboston.Tests.Bank
{
public class BlocksServiceTests
{
#region Test Models

private PaginatedResponseModel<BankBlock> CreateMockBlock()
{
return new PaginatedResponseModel<BankBlock>() {
Count = 1,
Next = string.Empty,
Previous = string.Empty,
Results =
new List<BankBlock>() {
new BankBlock {
Id = "c6fc11cf-8948-4d32-96c9-d56caa6d5b24",
Created = DateTime.Parse("2020-10-08T02:18:07.324999Z"),
Modified = DateTime.Parse("2020-10-08T02:18:07.325044Z"),
BalanceKey = "a37e2836805975f334108b55523634c995bd2a4db610062f404510617e83126f",
Sender = "a37e2836805975f334108b55523634c995bd2a4db610062f404510617e83126f",
Signature =
"a2ba346d98cb1f7ce6bf017240d674a9928796ddb564a2c8817e68ead0ea02d960e970fe581c6d3a25b9876e1873d51c882b23d843e32f511d9575ef60d2940d"
}
}
};
}

private Block CreateMockBlockMessage()
{
return new Block() {
AccountNumber = "0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb",
Message = new BlockMessage() {
BalanceKey = "ce51f0d9facaa7d3e69657429dd3f961ce70077a8efb53dcda508c7c0a19d2e3",
Transactions = new List<BlockTransaction>() {
new BlockTransaction() {
Amount = "12.5",
Recipient = "484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc"
},
new BlockTransaction() {
Amount = "1", Recipient = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8"
},
new BlockTransaction() {
Amount = "4", Recipient = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314"
}
}
},
Signature =
"ee5a2f2a2f5261c1b633e08dd61182fd0db5604c853ebd8498f6f28ce8e2ccbbc38093918610ea88a7ad47c7f3192ed955d9d1529e7e390013e43f25a5915c0f"
};
}

#endregion

#region Mock Service

private IBlocksService BuildBlockGetMock()
{
var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
response.Content = new StringContent(JsonConvert.SerializeObject(CreateMockBlock()), Encoding.UTF8,
"application/json");
var requestSenderMock = new Mock<IHttpRequestSender>();

requestSenderMock
.Setup(s => s.GetAsync(It.IsAny<string>()))
.ReturnsAsync(response);

IBlocksService service = new BlocksService(requestSenderMock.Object);
return service;
}

private IBlocksService BuildBlockPostMock()
{
var requestSenderMock = new Mock<IHttpRequestSender>();
requestSenderMock.Setup(s => s.PostAsync(It.IsAny<string>(), It.IsAny<HttpContent>()))
.ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.Created));

IBlocksService service = new BlocksService(requestSenderMock.Object);
return service;
}

#endregion

#region Tests

[Fact]
public async void BlockReturnedAsync()
{
var service = BuildBlockGetMock();
var returnedBlock = await service.GetBlocksAsync(0, 10);
var expectedResult = JsonConvert.SerializeObject(CreateMockBlock());
var actualResult = JsonConvert.SerializeObject(returnedBlock);
Assert.Equal(expectedResult, actualResult);
}

//TODO :remove
//[Fact]
//public async void BlockPostedAsync()
//{
// var service = BuildBlockPostMock();
// var response = await service.PostBlocksAsync(CreateMockBlockMessage());
// Assert.NotNull(response);
//}

#endregion
}
}
Loading

0 comments on commit ca44ade

Please sign in to comment.