Browse Source

Added basic tests for mongodb.

pull/272/head
Halil İbrahim Kalkan 9 years ago
parent
commit
0a2f6c3d5a
  1. 60
      test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDb_Repository_Tests.cs
  2. 4
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs

60
test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDb_Repository_Tests.cs

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Domain.Repositories;
@ -20,7 +21,64 @@ namespace Volo.Abp.MongoDB
[Fact]
public async Task GetAsync()
{
(await _personRepository.GetAsync(TestDataBuilder.UserDouglasId)).ShouldNotBeNull();
var person = await _personRepository.GetAsync(TestDataBuilder.UserDouglasId);
person.Name.ShouldBe("Douglas");
person.Phones.Count.ShouldBe(2);
}
[Fact]
public async Task FindAsync_Should_Return_Null_For_Not_Found_Entity()
{
var person = await _personRepository.FindAsync(Guid.NewGuid());
person.ShouldBeNull();
}
[Fact]
public void Linq_Queries()
{
_personRepository.FirstOrDefault(p => p.Name == "Douglas").ShouldNotBeNull();
_personRepository.Count().ShouldBeGreaterThan(0);
}
[Fact]
public async Task DeleteAsync()
{
await _personRepository.DeleteAsync(TestDataBuilder.UserDouglasId);
(await _personRepository.FindAsync(TestDataBuilder.UserDouglasId)).ShouldBeNull();
}
[Fact]
public async Task UpdateAsync()
{
var person = await _personRepository.GetAsync(TestDataBuilder.UserDouglasId);
person.ChangeName("Douglas-Updated");
person.Phones.Add(new Phone(person.Id, "6667778899", PhoneType.Office));
await _personRepository.UpdateAsync(person);
person = await _personRepository.FindAsync(TestDataBuilder.UserDouglasId);
person.ShouldNotBeNull();
person.Name.ShouldBe("Douglas-Updated");
person.Phones.Count.ShouldBe(3);
person.Phones.Any(p => p.PersonId == person.Id && p.Number == "6667778899" && p.Type == PhoneType.Office).ShouldBeTrue();
}
[Fact]
public async Task InsertAsync()
{
var person = new Person(Guid.NewGuid(), "New Person", 35);
person.Phones.Add(new Phone(person.Id, "1234567890"));
await _personRepository.InsertAsync(person);
person = await _personRepository.FindAsync(person.Id);
person.ShouldNotBeNull();
person.Name.ShouldBe("New Person");
person.Phones.Count.ShouldBe(1);
person.Phones.Any(p => p.PersonId == person.Id && p.Number == "1234567890").ShouldBeTrue();
}
}
}

4
test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs

@ -15,7 +15,7 @@ namespace Volo.Abp.TestApp.Domain
public virtual Collection<Phone> Phones { get; set; }
public bool IsDeleted { get; set; }
public virtual bool IsDeleted { get; set; }
private Person()
{
@ -32,7 +32,7 @@ namespace Volo.Abp.TestApp.Domain
Phones = new Collection<Phone>();
}
public void ChangeName(string name)
public virtual void ChangeName(string name)
{
Check.NotNullOrWhiteSpace(name, nameof(name));

Loading…
Cancel
Save