This repository has been archived by the owner on Jul 12, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more unit tests and fixed two issues with cosmos id
- Loading branch information
Showing
14 changed files
with
506 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Cosmonaut.Exceptions; | ||
using Cosmonaut.Response; | ||
using Xunit; | ||
|
||
namespace Cosmonaut.Tests | ||
{ | ||
public class CosmosAddTests | ||
{ | ||
private readonly ICosmosStore<Dummy> _dummyStore; | ||
|
||
public CosmosAddTests() | ||
{ | ||
_dummyStore = new InMemoryCosmosStore<Dummy>(); | ||
} | ||
|
||
[Fact] | ||
public async Task AddValidObjectSuccess() | ||
{ | ||
// Arrange | ||
var id = Guid.NewGuid().ToString(); | ||
var dummy = new Dummy | ||
{ | ||
Id = id, | ||
Name = "Nick" | ||
}; | ||
|
||
// Act | ||
var expectedResponse = new CosmosResponse<Dummy>(dummy, CosmosOperationStatus.Success); | ||
var result = await _dummyStore.AddAsync(dummy); | ||
|
||
//Assert | ||
Assert.Equal(expectedResponse.Entity, result.Entity); | ||
Assert.Equal(expectedResponse.IsSuccess, result.IsSuccess); | ||
} | ||
|
||
[Fact] | ||
public async Task AddEntityWithoutIdEmptyGeneratedId() | ||
{ | ||
// Arrange | ||
var dummy = new Dummy | ||
{ | ||
Name = "Nick" | ||
}; | ||
|
||
// Act | ||
var result = await _dummyStore.AddAsync(dummy); | ||
|
||
//Assert | ||
var isGuid = Guid.TryParse(result.Entity.Id, out var guid); | ||
Assert.True(isGuid); | ||
Assert.NotEqual(Guid.Empty, guid); | ||
} | ||
|
||
[Fact] | ||
public async Task AddingEntityWithoutIdThrowsException() | ||
{ | ||
// Arrange | ||
var dummy = new | ||
{ | ||
Name = "Name" | ||
}; | ||
|
||
// Act | ||
var addTask = new InMemoryCosmosStore<object>().AddAsync(dummy); | ||
|
||
//Assert | ||
await Assert.ThrowsAsync<CosmosEntityWithoutIdException<object>>(() => addTask); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Cosmonaut.Response; | ||
using Xunit; | ||
|
||
namespace Cosmonaut.Tests | ||
{ | ||
public class CosmosRemoveTests | ||
{ | ||
private readonly ICosmosStore<Dummy> _dummyStore; | ||
|
||
public CosmosRemoveTests() | ||
{ | ||
_dummyStore = new InMemoryCosmosStore<Dummy>(); | ||
} | ||
|
||
[Fact] | ||
public async Task RemoveEntityRemoves() | ||
{ | ||
// Assign | ||
var id = Guid.NewGuid().ToString(); | ||
var addedDummy = new Dummy | ||
{ | ||
Id = id, | ||
Name = "Test" | ||
}; | ||
await _dummyStore.AddAsync(addedDummy); | ||
|
||
// Act | ||
var result = await _dummyStore.RemoveAsync(addedDummy); | ||
|
||
// Assert | ||
Assert.True(result.IsSuccess); | ||
Assert.Equal(CosmosOperationStatus.Success, result.CosmosOperationStatus); | ||
} | ||
|
||
[Fact] | ||
public async Task RemoveByIdRemoves() | ||
{ | ||
// Assign | ||
var id = Guid.NewGuid().ToString(); | ||
var addedDummy = new Dummy | ||
{ | ||
Id = id, | ||
Name = "Test" | ||
}; | ||
await _dummyStore.AddAsync(addedDummy); | ||
|
||
// Act | ||
var result = await _dummyStore.RemoveByIdAsync(id); | ||
|
||
// Assert | ||
Assert.True(result.IsSuccess); | ||
Assert.Equal(CosmosOperationStatus.Success, result.CosmosOperationStatus); | ||
} | ||
|
||
[Fact] | ||
public async Task RemoveByExpressionRemoves() | ||
{ | ||
// Assign | ||
foreach (var i in Enumerable.Range(0, 10)) | ||
{ | ||
var id = Guid.NewGuid().ToString(); | ||
var addedDummy = new Dummy | ||
{ | ||
Id = id, | ||
Name = "Test " + i | ||
}; | ||
await _dummyStore.AddAsync(addedDummy); | ||
} | ||
|
||
// Act | ||
var result = await _dummyStore.RemoveAsync(x => x.Name.Contains("Test")); | ||
|
||
// Assert | ||
Assert.True(result.IsSuccess); | ||
Assert.Empty(result.FailedEntities); | ||
} | ||
|
||
[Fact] | ||
public async Task RemoveRangeRemoves() | ||
{ | ||
// Assign | ||
var addedList = new List<Dummy>(); | ||
foreach (var i in Enumerable.Range(0, 10)) | ||
{ | ||
var id = Guid.NewGuid().ToString(); | ||
var addedDummy = new Dummy | ||
{ | ||
Id = id, | ||
Name = "Test " + i | ||
}; | ||
await _dummyStore.AddAsync(addedDummy); | ||
addedList.Add(addedDummy); | ||
} | ||
|
||
// Act | ||
var result = await _dummyStore.RemoveRangeAsync(addedList); | ||
|
||
// Assert | ||
Assert.True(result.IsSuccess); | ||
Assert.Empty(result.FailedEntities); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Cosmonaut.Response; | ||
using Xunit; | ||
|
||
namespace Cosmonaut.Tests | ||
{ | ||
public class CosmosUpdateTests | ||
{ | ||
private readonly ICosmosStore<Dummy> _dummyStore; | ||
|
||
public CosmosUpdateTests() | ||
{ | ||
_dummyStore = new InMemoryCosmosStore<Dummy>(); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateEntityUpdates() | ||
{ | ||
// Arrange | ||
var id = Guid.NewGuid().ToString(); | ||
var addedDummy = new Dummy | ||
{ | ||
Id = id, | ||
Name = "Test" | ||
}; | ||
var expectedName = "NewTest"; | ||
await _dummyStore.AddAsync(addedDummy); | ||
|
||
// Act | ||
addedDummy.Name = expectedName; | ||
var result = await _dummyStore.UpdateAsync(addedDummy); | ||
|
||
// Assert | ||
Assert.Equal(expectedName, result.Entity.Name); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateRangeUpdatesEntities() | ||
{ | ||
// Arrange | ||
var addedEntities = new List<Dummy>(); | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
var id = Guid.NewGuid().ToString(); | ||
var addedDummy = new Dummy | ||
{ | ||
Id = id, | ||
Name = "UpdateMe" | ||
}; | ||
var added = await _dummyStore.AddAsync(addedDummy); | ||
addedEntities.Add(added.Entity); | ||
} | ||
|
||
// Act | ||
var result = await _dummyStore.UpdateRangeAsync(); | ||
|
||
// Assert | ||
Assert.True(result.IsSuccess); | ||
Assert.Empty(result.FailedEntities); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateEntityThatHasIdChangedFails() | ||
{ | ||
// Arrange | ||
var id = Guid.NewGuid().ToString(); | ||
var addedDummy = new Dummy | ||
{ | ||
Id = id, | ||
Name = "Test" | ||
}; | ||
await _dummyStore.AddAsync(addedDummy); | ||
|
||
// Act | ||
addedDummy.Id = Guid.NewGuid().ToString(); | ||
var result = await _dummyStore.UpdateAsync(addedDummy); | ||
|
||
// Assert | ||
Assert.False(result.IsSuccess); | ||
Assert.Equal(CosmosOperationStatus.ResourceNotFound, result.CosmosOperationStatus); | ||
} | ||
} | ||
} |
Oops, something went wrong.