dotnet-object-storage/PoweredSoft.ObjectStorage.MongoDB.Tests/CrudTests.cs

57 lines
1.8 KiB
C#
Raw Normal View History

2019-02-12 17:39:16 -05:00
using System;
using System.Linq;
using System.Threading.Tasks;
using PoweredSoft.ObjectStorage.MongoDB.Tests.Mock;
using PoweredSoft.ObjectStorage.MongoDB.Tests.Mock.Dal;
using Xunit;
namespace PoweredSoft.ObjectStorage.MongoDB.Tests
{
public class CrudTests
{
[Fact]
public async Task CreateUpdateThenDelete()
{
2019-02-12 23:39:55 -05:00
var osc = MongoDatabaseFactory.GetObjectStorageContext();
2019-02-12 17:39:16 -05:00
var collection = osc.GetCollection<Contact>();
var contact = await collection.AddAsync(new Contact
{
FirstName = "Chuck",
LastName = "Not Norris"
});
Assert.NotNull(contact);
contact.LastName = "Norris";
var updatedContact = await collection.UpdateAsync(contact);
Assert.Equal("Norris", updatedContact.LastName);
// delete the test.
await collection.DeleteAsync(updatedContact);
// check that it was deleted.
var shouldBeNull = collection.AsQueryable().FirstOrDefault(t => t.Id == updatedContact.Id);
Assert.Null(shouldBeNull);
}
2019-02-12 22:53:22 -05:00
[Fact]
public async Task TestGetAsync()
{
2019-02-12 23:39:55 -05:00
var osc = MongoDatabaseFactory.GetObjectStorageContext();
2019-02-12 22:53:22 -05:00
var collection = osc.GetCollection<Contact>();
var contact = await collection.AddAsync(new Contact
{
FirstName = "David",
LastName = "Lebee"
});
// make sure you can retreive it easily.
var fetchedUsingGetAsync = await collection.GetAsync(contact.Id);
Assert.NotNull(fetchedUsingGetAsync);
// now delete it.
await collection.DeleteAsync(fetchedUsingGetAsync);
}
2019-02-12 17:39:16 -05:00
}
}