gx
This commit is contained in:
1 parent
c2dcedd238
commit
16cdd3d46e
34 files changed
+837
-481
No files matched your search
@@ -1,4 +1,4 @@
|
||||
using Autofac;
|
||||
using Autofac;
|
||||
using LittleCow.Core.Infrastructure;
|
||||
using MAX.Core.Autofac;
|
||||
using MAX.Core.Cryptography;
|
||||
@@ -7,6 +7,10 @@ using Store.Client;
|
||||
using Store.Client.Apis;
|
||||
using Store.Client.HttpExtension;
|
||||
using Store.Client.Services;
|
||||
using Store.Framework.Models;
|
||||
using Store.Product.Models.Product;
|
||||
using Store.Product.Publish;
|
||||
using Store.Product.Publish.Steps.Wx;
|
||||
|
||||
namespace Store.Test;
|
||||
|
||||
@@ -15,7 +19,8 @@ public class Tests
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Bootstrap.Builder();
|
||||
Bootstrap.Builder();
|
||||
TestUserLogin();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -28,5 +33,156 @@ public class Tests
|
||||
});
|
||||
//new UserApi().Login("18990991234", MD5Helper.Md5_Lower32("18990991234"));
|
||||
}
|
||||
[Test]
|
||||
public void TestGetShops()
|
||||
{
|
||||
var ss = IocManager.Resolve<ShopManager>().GetShops();
|
||||
}
|
||||
[Test]
|
||||
public void TestNewWxUploadProductUsesProductBase()
|
||||
{
|
||||
var context = new WXPublishContext();
|
||||
var product = new WxProductUploadProduct
|
||||
{
|
||||
Title = "新版微信商品",
|
||||
SpuId = "wx-spu-1001",
|
||||
WxCatLeaf = 547591
|
||||
};
|
||||
|
||||
}
|
||||
context.Product = product;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(context.Product, Is.TypeOf<WxProductUploadProduct>());
|
||||
Assert.That(context.Product, Is.InstanceOf<ProductBase>());
|
||||
Assert.That(((PublishContextBase)context).Product, Is.SameAs(product));
|
||||
Assert.That(context.Product.Title, Is.EqualTo("新版微信商品"));
|
||||
Assert.That(context.Product.WxCatLeaf, Is.EqualTo(547591));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestNewWxUploadFissionTitleUpdatesProductModel()
|
||||
{
|
||||
var context = new WXPublishContext
|
||||
{
|
||||
Product = new WxProductUploadProduct { Title = "原商品标题" },
|
||||
Progress = new Progress<string>(_ => { })
|
||||
};
|
||||
context.Parameters.IsFissionTitle = true;
|
||||
context.Parameters.FissionTitles = "裂变标题一\r\n裂变标题二";
|
||||
|
||||
var step = new FissionTitleStep();
|
||||
await step.ExecuteAsync(context, CancellationToken.None);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(context.Product.Title, Is.EqualTo("裂变标题一"));
|
||||
Assert.That(context.Parameters.IsFissionTitle, Is.True);
|
||||
Assert.That(context.Parameters.FissionTitles, Is.EqualTo("裂变标题二"));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestNewWxUploadSetTitleWritesFinalParameters()
|
||||
{
|
||||
var context = new WXPublishContext
|
||||
{
|
||||
Product = new WxProductUploadProduct { Title = "最终上传标题" },
|
||||
Progress = new Progress<string>(_ => { })
|
||||
};
|
||||
|
||||
var step = new SetProductTitleStep();
|
||||
await step.ExecuteAsync(context, CancellationToken.None);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(context.Parameters.InitParameter.product.info.title, Is.EqualTo("最终上传标题"));
|
||||
Assert.That(context.Parameters.ProductParameter.product.info.title, Is.EqualTo("最终上传标题"));
|
||||
Assert.That(
|
||||
context.Parameters.ProductParameter.sessionInfo.sessionId,
|
||||
Is.EqualTo(context.Parameters.InitParameter.product.sessionId));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestNewWxUploadPipelineRunsCompositionToSubmit()
|
||||
{
|
||||
var context = new WXPublishContext
|
||||
{
|
||||
Shop = new Shop
|
||||
{
|
||||
Name = "乐乐人小店",
|
||||
Cookie = new Cookies("biz_token=b_000001a0_80071145_44612ea2_a87897a5_12c2c339; biz_ticket=; biz_magic=09bcc3e825c8826c562d62ca3442e35e8eb4ce13b73e4097661f11c9bd90f46e; biz_rand=CAESIO762C8Iu/hxVBpyNsXZiqDGlOsa5U3WBKBd3PvU0p6d; device_id=7b7080668b28f2aadba6d7f208ca35833c4ce75fe4c107eca6a5e5785fccc8ad")
|
||||
},
|
||||
Product = new WxProductUploadProduct { Title = "原商品标题" },
|
||||
Progress = new Progress<string>(_ => { })
|
||||
};
|
||||
context.Parameters.IsFissionTitle = true;
|
||||
context.Parameters.FissionTitles = "裂变商品标题";
|
||||
|
||||
var pipeline = new WXPublishPipeline(new IPublishStep<WXPublishContext>[]
|
||||
{
|
||||
new FissionTitleStep(),
|
||||
new SkipUploadedProductStep(),
|
||||
new SetProductTitleStep(),
|
||||
new TestSubmitProductStep()
|
||||
});
|
||||
|
||||
await pipeline.ExecuteAsync(context, CancellationToken.None);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(context.Product.Title, Is.EqualTo("裂变商品标题"));
|
||||
Assert.That(context.Parameters.InitParameter.product.info.title, Is.EqualTo("裂变商品标题"));
|
||||
Assert.That(context.Parameters.ProductParameter.product.info.title, Is.EqualTo("裂变商品标题"));
|
||||
Assert.That(context.Parameters.Result, Is.EqualTo("{\"success\":true}"));
|
||||
Assert.That(context.Parameters.IsCompleted, Is.True);
|
||||
});
|
||||
}
|
||||
|
||||
private sealed class TestSubmitProductStep : IPublishStep<WXPublishContext>
|
||||
{
|
||||
public string Description => "测试提交商品";
|
||||
|
||||
public Task<bool> CanExecuteAsync(WXPublishContext context, CancellationToken token)
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public Task ExecuteAsync(WXPublishContext context, CancellationToken token)
|
||||
{
|
||||
var title = context.Parameters.ProductParameter.product.info.title;
|
||||
if (title != context.Product.Title)
|
||||
{
|
||||
throw new InvalidOperationException("提交参数中的标题不是最终组合标题。");
|
||||
}
|
||||
|
||||
context.Parameters.Result = "{\"success\":true}";
|
||||
context.Parameters.IsCompleted = true;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class AlwaysExecuteStep : IPublishStep<WXPublishContext>
|
||||
{
|
||||
private readonly IPublishStep<WXPublishContext> _inner;
|
||||
|
||||
public AlwaysExecuteStep(IPublishStep<WXPublishContext> inner)
|
||||
{
|
||||
_inner = inner;
|
||||
}
|
||||
|
||||
public string Description => _inner.Description;
|
||||
|
||||
public Task<bool> CanExecuteAsync(WXPublishContext context, CancellationToken token)
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public Task ExecuteAsync(WXPublishContext context, CancellationToken token)
|
||||
{
|
||||
return _inner.ExecuteAsync(context, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user