Commit c771ea77 by 丁松杰

添加 orleans entityframework 集成测试

parent be19a9e3
......@@ -21,7 +21,7 @@ namespace Product.Api.Controllers
[HttpGet("AddProductType")]
public void AddProductType(string name = "test")
{
var newId = Guid.NewGuid().ToString("N").ToLower();
var newId = "da8a489fa7b4409294ee1b358fbbfba5";
var grain = clusterClient.GetGrain<IProductTypeGrain>(newId);
grain.AddProductType(newId, name);
}
......
using Orleans;
using Pole.Core.Grains;
using Product.Api.Domain.AggregatesModel.ProductTypeAggregate;
using Product.Api.Grains.Abstraction;
using System;
......@@ -8,7 +9,7 @@ using System.Threading.Tasks;
namespace Product.Api.Grains
{
public class ProductTypeGrain : Grain<ProductType>, IProductTypeGrain
public class ProductTypePoleGrainGrain : PoleGrain<ProductType>, IProductTypeGrain
{
public async Task<bool> AddProductType(string id, string name)
{
......@@ -20,6 +21,7 @@ namespace Product.Api.Grains
Name = name
};
State = productType;
Add(productType);
await WriteStateAsync();
return true;
}
......
......@@ -18,6 +18,7 @@ namespace Product.Api.Infrastructure.EntityConfigurations
builder.Property(m => m.Name).HasMaxLength(256).IsRequired();
builder.Ignore(m => m.DomainEvents);
builder.Ignore(m => m.IsPersisted);
builder.HasKey(m => m.Id);
}
......
......@@ -20,6 +20,8 @@ namespace Pole.Core.Domain
}
}
public List<IEvent> DomainEvents { get; private set; }
public bool IsPersisted { get; set; }
public bool IsTransient()
{
return string.IsNullOrEmpty(this._id);
......
using Orleans;
using Pole.Core.Domain;
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Core.Grains
{
public abstract class PoleGrain<TAggregateRoot> : Grain<TAggregateRoot>, IGrainWithStringKey
where TAggregateRoot : Entity, IAggregateRoot, new()
{
public void Update(TAggregateRoot aggregateRoot)
{
aggregateRoot.IsPersisted = true;
}
public void Add(TAggregateRoot aggregateRoot)
{
aggregateRoot.IsPersisted = false;
}
}
}
......@@ -10,6 +10,6 @@ namespace Pole.Orleans.Provider.EntityframeworkCore.Conventions
public string DefaultGrainKeyExtPropertyName { get; set; } = "KeyExt";
public string DefaultPersistenceCheckPropertyName { get; set; } = "Id";
public string DefaultPersistenceCheckPropertyName { get; set; } = "IsPersisted";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment