Skip to content

Commit

Permalink
Added tests for ExtraProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
hikalkan committed Feb 19, 2019
1 parent 73ad39e commit d07a689
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
@@ -0,0 +1,9 @@
using Volo.Abp.TestApp.Testing;

namespace Volo.Abp.EntityFrameworkCore.Domain
{
public class ExtraProperties_Tests : ExtraProperties_Tests<AbpEntityFrameworkCoreTestModule>
{

}
}
@@ -0,0 +1,9 @@
using Volo.Abp.TestApp.Testing;

namespace Volo.Abp.MongoDB.Domain
{
public class ExtraProperties_Tests : ExtraProperties_Tests<AbpMongoDbTestModule>
{

}
}
Expand Up @@ -36,7 +36,7 @@ private void AddCities()
{
_cityRepository.Insert(new City(Guid.NewGuid(), "Tokyo"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Madrid"));
_cityRepository.Insert(new City(LondonCityId, "London"));
_cityRepository.Insert(new City(LondonCityId, "London") {ExtraProperties = { { "Population", 10_470_000 } } });
_cityRepository.Insert(new City(IstanbulCityId, "Istanbul"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Paris"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Washington"));
Expand Down
@@ -0,0 +1,53 @@
using System;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Modularity;
using Volo.Abp.TestApp.Domain;
using Xunit;

namespace Volo.Abp.TestApp.Testing
{
public abstract class ExtraProperties_Tests<TStartupModule> : TestAppTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
protected readonly ICityRepository CityRepository;

protected ExtraProperties_Tests()
{
CityRepository = GetRequiredService<ICityRepository>();
}

[Fact]
public async Task Should_Get_An_Extra_Property()
{
var london = await CityRepository.FindByNameAsync("London");
london.ExtraProperties.ContainsKey("Population").ShouldBeTrue();
london.ExtraProperties["Population"].To<int>().ShouldBe(10_470_000);
}

[Fact]
public async Task Should_Add_An_Extra_Property()
{
var london = await CityRepository.FindByNameAsync("London");
london.ExtraProperties["AreaAsKm"] = 1572;
await CityRepository.UpdateAsync(london);

var london2 = await CityRepository.FindByNameAsync("London");
london2.ExtraProperties.ContainsKey("AreaAsKm").ShouldBeTrue();
london2.ExtraProperties["AreaAsKm"].To<int>().ShouldBe(1572);
}

[Fact]
public async Task Should_Update_An_Existing_Extra_Property()
{
var london = await CityRepository.FindByNameAsync("London");

london.ExtraProperties["Population"] = 11_000_042;
await CityRepository.UpdateAsync(london);

var london2 = await CityRepository.FindByNameAsync("London");
london2.ExtraProperties.ContainsKey("Population").ShouldBeTrue();
london2.ExtraProperties["Population"].To<int>().ShouldBe(11_000_042);
}
}
}

0 comments on commit d07a689

Please sign in to comment.