示例#1
0
            public void TestMethod1()
            {
                try
                {
                    var fabric    = new ManualFabricBridge();
                    var bridgeOut = fabric[FabricMode.Queue];
                    var bridgein  = fabric[FabricMode.Broadcast];

                    var key = CreateSalt(128);

                    var encOut = new AesEncryptionHandler(key, keySize: 128);
                    var encIn  = new AesEncryptionHandler(key, keySize: 128);


                    PersistenceClient <Guid, SecureMe> init;
                    DebugMemoryDataCollector           memp1, memp2;

                    var p1 = new MicroservicePipeline("Sender")
                             .AddEncryptionHandler("rogue1", encOut)
                             .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault   = true)
                             .AddDataCollector((c) => new DebugMemoryDataCollector(), (c) => memp1 = c)
                             .AddChannelIncoming("cresponse")
                             .AttachListener(bridgein.GetListener())
                             .Revert()
                             .AddChannelOutgoing("crequest")
                             .AttachTransportPayloadEncryption("rogue1")
                             .AttachSender(bridgeOut.GetSender())
                             .AttachPersistenceClient("cresponse", out init)
                             .Revert()
                    ;

                    var p2 = new MicroservicePipeline("Receiver")
                             .AddEncryptionHandler("rogue2", encIn)
                             .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault   = true)
                             .AddDataCollector((c) => new DebugMemoryDataCollector(), (c) => memp2 = c)
                             .AddChannelIncoming("crequest")
                             .AttachTransportPayloadDecryption("rogue2")
                             .AttachListener(bridgeOut.GetListener())
                             .AttachCommand(new PersistenceManagerHandlerMemory <Guid, SecureMe>((e) => e.Id, (s) => new Guid(s)))
                             .Revert()
                             .AddChannelOutgoing("cresponse")
                             .AttachSender(bridgein.GetSender())
                    ;

                    p1.Start();
                    p2.Start();

                    int check1 = p1.ToMicroservice().Commands.Count();
                    int check2 = p2.ToMicroservice().Commands.Count();

                    var entity = new SecureMe()
                    {
                        Message = "Momma"
                    };
                    var rs = init.Create(entity, new RepositorySettings()
                    {
                        WaitTime = TimeSpan.FromMinutes(5)
                    }).Result;
                    var rs2 = init.Read(entity.Id).Result;

                    Assert.IsTrue(rs2.IsSuccess);
                    Assert.IsTrue(rs2.Entity.Message == "Momma");
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
示例#2
0
            public void TestMethod1()
            {
                try
                {
                    var fabric    = new ManualFabricBridge();
                    var bridgeOut = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.RoundRobin);
                    var bridgein  = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.Broadcast);

                    PersistenceClient <Guid, SecureMe> init;
                    DebugMemoryDataCollector           memp1, memp2;

                    var p1 = new MicroservicePipeline("Sender")
                             .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                             .AddAuthenticationHandlerJwtToken("id1", JwtHashAlgorithm.HS256, Encoding.UTF8.GetBytes("My big secret"))
                             .AddDebugMemoryDataCollector(out memp1)
                             .AddChannelIncoming("cresponse", boundaryLoggingEnabled: true)
                             .AttachListener(bridgein.GetListener())
                             .Revert()
                             .AddChannelOutgoing("crequest", boundaryLoggingEnabled: true)
                             .AttachSender(bridgeOut.GetSender())
                             .AttachTransportPayloadSignature("id1")
                             .AttachPersistenceClient("cresponse", out init)
                             .Revert()
                    ;

                    var p2 = new MicroservicePipeline("Receiver")
                             .AdjustPolicyCommunication((p, c) => p.BoundaryLoggingActiveDefault = true)
                             .AddAuthenticationHandlerJwtToken("id1", JwtHashAlgorithm.HS256, Encoding.UTF8.GetBytes("My big secret"))
                             .AddDebugMemoryDataCollector(out memp2)
                             .AddChannelIncoming("crequest", boundaryLoggingEnabled: true)
                             .AttachListener(bridgeOut.GetListener())
                             .AttachTransportPayloadVerification("id1")
                             .AttachCommand(new PersistenceManagerHandlerMemory <Guid, SecureMe>((e) => e.Id, (s) => new Guid(s)))
                             .Revert()
                             .AddChannelOutgoing("cresponse", boundaryLoggingEnabled: true)
                             .AttachSender(bridgein.GetSender())
                             .Revert()
                    ;

                    p1.Start();
                    p2.Start();

                    int check1 = p1.ToMicroservice().Commands.Count();
                    int check2 = p2.ToMicroservice().Commands.Count();

                    var entity = new SecureMe()
                    {
                        Message = "Momma"
                    };
                    var rs = init.Create(entity, new RepositorySettings()
                    {
                        WaitTime = TimeSpan.FromSeconds(30)
                    }).Result;
                    var rs2 = init.Read(entity.Id).Result;

                    Assert.IsTrue(rs2.IsSuccess);
                    Assert.IsTrue(rs2.Entity.Message == "Momma");
                }
                catch (Exception ex)
                {
                    throw;
                }
            }