public void UploadenBestandFaalendBestandCursusStartdatum() { //Arrange using (var ms = new MemoryStream()) { using (var writer = new StreamWriter(ms)) { var fileMock = new Mock <IFormFile>(); writer.WriteLine("Titel: C# Programmeren"); writer.WriteLine("Cursuscode: CNETIN"); writer.WriteLine("Duur: 5 dagen"); writer.WriteLine("11/10/2014 "); writer.WriteLine(""); writer.Flush(); ms.Position = 0; fileMock.Setup(m => m.OpenReadStream()).Returns(ms); fileMock.Setup(m => m.Length).Returns(5); MockAgent mockAgent = new MockAgent(); var target = new CursusController(mockAgent); //Act var result = target.Create(fileMock.Object); // Assert CursusCreateMessageViewModel viewModel = (CursusCreateMessageViewModel)(result as ViewResult).Model; Assert.IsNotNull(viewModel); Assert.AreEqual(4, viewModel.ErrorAtLine); } } }
public void TestenFileUploadOntvangenBijController() { //Arrange using (var ms = new MemoryStream()) { using (var writer = new StreamWriter(ms)) { var fileMock = new Mock <IFormFile>(); writer.WriteLine("Titel: C# Programmeren"); writer.WriteLine("Cursuscode: CNETIN"); writer.WriteLine("Duur: 5 dagen"); writer.WriteLine("Startdatum: 11/10/2014 "); writer.WriteLine(""); writer.Flush(); ms.Position = 0; fileMock.Setup(m => m.OpenReadStream()).Returns(ms); fileMock.Setup(m => m.Length).Returns(5); MockAgent mockAgent = new MockAgent(); var target = new CursusController(mockAgent); //Act var result = target.Create(fileMock.Object); //Assert Assert.IsInstanceOfType(result, typeof(IActionResult)); } } }
public void UploadenBestandTestAddContentVolledigeCursusTitelCheck() { //Arrange using (var ms = new MemoryStream()) { using (var writer = new StreamWriter(ms)) { var fileMock = new Mock <IFormFile>(); writer.WriteLine("Titel: C# Programmeren"); writer.WriteLine("Cursuscode: CNETIN"); writer.WriteLine("Duur: 5 dagen"); writer.WriteLine("Startdatum: 11/10/2014 "); writer.WriteLine(""); writer.Flush(); ms.Position = 0; fileMock.Setup(m => m.OpenReadStream()).Returns(ms); fileMock.Setup(m => m.Length).Returns(5); MockAgent mockAgent = new MockAgent(); var target = new CursusController(mockAgent); //Act var result = target.Create(fileMock.Object); //Assert Assert.AreEqual(1, mockAgent.NumberOfTimesAddCalled); Assert.AreEqual("C# Programmeren", mockAgent.LijstCursusAddToevoeging[0].Cursus.Titel); } } }
public static async Task ProofProtocolConnectionlessAsync(MockAgent requestor, MockAgent holder, ProofRequest proofRequest, bool useDidKeyFormat) { var proofService = requestor.GetService <IProofService>(); var(requestMsg, requestorRecord) = await proofService.CreateRequestAsync(requestor.Context, proofRequest, useDidKeyFormat : useDidKeyFormat); var requestAttachment = requestMsg.Requests.FirstOrDefault(x => x.Id == "libindy-request-presentation-0") ?? throw new ArgumentException("Presentation request attachment not found."); var requestJson = requestAttachment.Data.Base64.GetBytesFromBase64().GetUTF8String(); var request = JsonConvert.DeserializeObject <ProofRequest>(requestJson); var requestedCredentials = await ProofServiceUtils.GetAutoRequestedCredentialsForProofCredentials(holder.Context, proofService, request); var holderRecord = await proofService.CreatePresentationAsync(holder.Context, requestMsg, requestedCredentials); var requestorProofRecord = await proofService.GetAsync(requestor.Context, requestorRecord.Id); var holderProofRecord = await proofService.GetAsync(holder.Context, holderRecord.Id); Assert.True(requestorProofRecord.State == ProofState.Accepted); Assert.True(holderProofRecord.State == ProofState.Accepted); var isProofValid = await proofService.VerifyProofAsync(requestor.Context, requestorProofRecord.Id); Assert.True(isProofValid); }
public void UploadenBestandTestVerwijzingMessagePage() { // Arrange var fileMock = new Mock <IFormFile>(); var lines = File.ReadLines(@"TestFile\goedvoorbeeld.txt").ToList(); using (var memoryStream = new MemoryStream()) { using (var streamWriter = new StreamWriter(memoryStream)) { for (var i = 0; i < lines.Count; i++) { streamWriter.WriteLine(lines[i]); } streamWriter.Flush(); memoryStream.Position = 0; fileMock.Setup(m => m.OpenReadStream()).Returns(memoryStream); fileMock.Setup(m => m.Length).Returns(5); MockAgent mockAgent = new MockAgent(); var target = new CursusController(mockAgent); //Act var result = target.Create(fileMock.Object); // Assert Assert.IsInstanceOfType(result, typeof(IActionResult)); Assert.AreEqual("CursusCreateMessage", (result as ViewResult).ViewName); } } }
public void UploadenBestandTestVerwijzingMessagePageModelContentInsertCount4() { // Arrange var fileMock = new Mock <IFormFile>(); var lines = File.ReadLines(@"TestFile\goedvoorbeeld.txt").ToList(); using (var memoryStream = new MemoryStream()) { using (var streamWriter = new StreamWriter(memoryStream)) { for (var i = 0; i < lines.Count; i++) { streamWriter.WriteLine(lines[i]); } streamWriter.Flush(); memoryStream.Position = 0; fileMock.Setup(m => m.OpenReadStream()).Returns(memoryStream); fileMock.Setup(m => m.Length).Returns(5); MockAgent mockAgent = new MockAgent(); var target = new CursusController(mockAgent); //Act var result = target.Create(fileMock.Object); // Assert CursusCreateMessageViewModel viewModel = (CursusCreateMessageViewModel)(result as ViewResult).Model; Assert.IsNotNull(viewModel); Assert.AreEqual(4, viewModel.SuccesInsertCount); } } }
public static string CreateBasicMessageWithHttpsType(MockAgent HttpsMessageAgent) { var basicMessage = new BasicMessage(HttpsMessageAgent.Context.UseMessageTypesHttps); Assert.Equal(MessageTypesHttps.BasicMessageType, basicMessage.Type); return(basicMessage.Type); }
public async Task InitializeAsync() { _agent1 = await MockUtils.CreateAsync("agent1", config1, cred, new MockAgentHttpHandler((cb) => _router.RouteMessage(cb.name, cb.data))); _router.RegisterAgent(_agent1); _agent2 = await MockUtils.CreateAsync("agent2", config2, cred, new MockAgentHttpHandler((cb) => _router.RouteMessage(cb.name, cb.data))); _router.RegisterAgent(_agent2); }
public void testAddObjectTwice() { Assert.assertEquals(1, env.getAgents().size()); XYLocation loc = new XYLocation(5, 5); AbstractAgent b = new MockAgent(); env.addObjectToLocation(b, loc); Assert.assertEquals(2, env.getAgents().size()); Assert.assertEquals(loc, env.getCurrentLocationFor(b)); }
public async Task InitializeAsync() { _issuerAgent = await MockUtils.CreateAsync("issuer", config1, cred, new MockAgentHttpHandler((cb) => _router.RouteMessage(cb.name, cb.data)), TestConstants.StewartDid); _router.RegisterAgent(_issuerAgent); _holderAgent = await MockUtils.CreateAsync("holder", config2, cred, new MockAgentHttpHandler((cb) => _router.RouteMessage((cb).name, cb.data))); _router.RegisterAgent(_holderAgent); }
public static async Task ProofProtocolAsync(MockAgent requestor, MockAgent holder, ConnectionRecord requestorConnection, ConnectionRecord holderConnection, ProofRequest proofRequest) { var proofService = requestor.GetService <IProofService>(); var messageService = requestor.GetService <IMessageService>(); // Hook into message event var requestSlim = new SemaphoreSlim(0, 1); holder.GetService <IEventAggregator>().GetEventByType <ServiceMessageProcessingEvent>() .Where(x => x.MessageType == MessageTypes.PresentProofNames.RequestPresentation) .Subscribe(x => requestSlim.Release()); var(requestMsg, requestorRecord) = await proofService.CreateRequestAsync(requestor.Context, proofRequest, requestorConnection.Id); await messageService.SendAsync(requestor.Context, requestMsg, requestorConnection); await requestSlim.WaitAsync(TimeSpan.FromSeconds(30)); var holderRequests = await proofService.ListRequestedAsync(holder.Context); Assert.NotNull(holderRequests); Assert.True(holderRequests.Count > 0); // Hook into message event var proofSlim = new SemaphoreSlim(0, 1); requestor.GetService <IEventAggregator>().GetEventByType <ServiceMessageProcessingEvent>() .Where(x => x.MessageType == MessageTypes.PresentProofNames.Presentation) .Subscribe(x => requestSlim.Release()); var record = holderRequests.FirstOrDefault(); var request = JsonConvert.DeserializeObject <ProofRequest>(record.RequestJson); var requestedCredentials = await ProofServiceUtils.GetAutoRequestedCredentialsForProofCredentials(holder.Context, proofService, request); var(proofMsg, holderRecord) = await proofService.CreatePresentationAsync(holder.Context, record.Id, requestedCredentials); await messageService.SendAsync(holder.Context, proofMsg, holderConnection); await proofSlim.WaitAsync(TimeSpan.FromSeconds(30)); var requestorProofRecord = await proofService.GetAsync(requestor.Context, requestorRecord.Id); var holderProofRecord = await proofService.GetAsync(holder.Context, holderRecord.Id); Assert.True(requestorProofRecord.State == ProofState.Accepted); Assert.True(holderProofRecord.State == ProofState.Accepted); var isProofValid = await proofService.VerifyProofAsync(requestor.Context, requestorProofRecord.Id); Assert.True(isProofValid); }
public override async Task <Scynet.Void> AgentStart(AgentStartRequest request, ServerCallContext context) { MockAgent egg = new MockAgent { Id = request.Egg.Uuid, EggData = request.Egg.EggData.ToByteArray() }; await client.GetGrain <IAgentRegistryGrain>(0).AgentStart(egg); return(new Scynet.Void()); }
public void FindAllCursist() { //Arrange MockAgent mockAgent = new MockAgent(); var target = new CursistController(mockAgent); //Act target.Index(); //Assert Assert.AreEqual(1, mockAgent.NumberOfTimesIndexCursistCalled); }
public void WeergevenHuidigeWeek() { //Arrange MockAgent mockAgent = new MockAgent(); var target = new CursusController(mockAgent); //Act var result = target.Index(); //Assert Assert.IsInstanceOfType(result, typeof(IActionResult)); }
public void RotateRollLeftOneWithRotation() { IAgent agent = new MockAgent() { MaxRotationSpeed = Rotation.One, Rotation = Quaternion.identity }; AgentController controller = new AgentController(agent); Rotation Rotate = Rotation.RollLeft; controller.Rotate(Rotate); Assert.AreEqual(359, agent.Rotation.eulerAngles.z); }
public void MoveRiseOneWithVector3() { IAgent agent = new MockAgent() { MaxMovementSpeed = Movement.One, Position = Vector3.zero }; AgentController controller = new AgentController(agent); Vector3 Direction = Vector3.zero + Movement.Up; controller.Move(Direction); Assert.AreEqual(1, agent.Position.y); }
public void MoveForwardOneWithMovement() { IAgent agent = new MockAgent() { MaxMovementSpeed = Movement.One, Position = Vector3.zero }; AgentController controller = new AgentController(agent); Movement Direction = Movement.Front; controller.Move(Direction); Assert.AreEqual(1, agent.Position.z); }
public async Task InitializeAsync() { _responder = await MockUtils.CreateAsync("responder", config1, cred, new MockAgentHttpHandler((cb) => _router.RouteMessage(cb.name, cb.data)), TestConstants.StewardSeed); _router.RegisterAgent(_responder); _requester = await MockUtils.CreateAsync("requester", config2, cred, new MockAgentHttpHandler((cb) => _router.RouteMessage(cb.name, cb.data))); _router.RegisterAgent(_requester); var ledgerService = _responder.ServiceProvider.GetRequiredService <ILedgerService>(); await ledgerService.RegisterServiceEndpointAsync(_responder.Context, TestConstants.StewardDid, "http://responder"); }
public void WeergevenGekozenWeekModelCheckContent() { //Arrange MockAgent mockAgent = new MockAgent(); var target = new CursusController(mockAgent); //Act var result = target.Index(40, 2016); //Assert var resultModel = (result as ViewResult).Model; Assert.IsInstanceOfType(resultModel, typeof(IEnumerable <CursusInstantie>)); Assert.AreEqual(new DateTime(2016, 10, 03).Day, DateTime.Parse(mockAgent.LijstGetByWeekInput[0]).Day); }
public void WeergevenHuidigeWeekModelCheck() { //Arrange MockAgent mockAgent = new MockAgent(); var target = new CursusController(mockAgent); //Act var result = target.Index(41, 2016); //Assert var resultModel = (result as ViewResult).Model; Assert.IsInstanceOfType(result, typeof(IActionResult)); Assert.IsInstanceOfType(resultModel, typeof(IEnumerable <CursusInstantie>)); }
public Task AgentStart(MockAgent egg) { MockAgent agent = new MockAgent(egg); if (!State.Agents.ContainsKey(agent.Id)) { agent.Start(); State.Agents.Add(agent.Id, agent); return(base.WriteStateAsync()); } if (!State.Agents[agent.Id].IsRunning) { State.Agents[agent.Id].Start(); return(base.WriteStateAsync()); } return(Task.CompletedTask); }
public static async Task IssueCredentialConnectionlessAsync(MockAgent issuer, MockAgent holder, List <CredentialPreviewAttribute> credentialAttributes, bool useDidKeyFormat) { var credentialService = issuer.GetService <ICredentialService>(); var schemaService = issuer.GetService <ISchemaService>(); var provisionService = issuer.GetService <IProvisioningService>(); var issuerProv = await provisionService.GetProvisioningAsync(issuer.Context.Wallet); var(definitionId, _) = await Scenarios.CreateDummySchemaAndNonRevokableCredDef(issuer.Context, schemaService, issuerProv.IssuerDid, credentialAttributes.Select(_ => _.Name).ToArray()); (var offer, var issuerCredentialRecord) = await credentialService.CreateOfferAsync( agentContext : issuer.Context, config : new OfferConfiguration { IssuerDid = issuerProv.IssuerDid, CredentialDefinitionId = definitionId, CredentialAttributeValues = credentialAttributes, UseDidKeyFormat = useDidKeyFormat }); var holderCredentialRecord = await credentialService.CreateCredentialAsync(holder.Context, offer); Assert.NotNull(holderCredentialRecord.CredentialAttributesValues); Assert.True(holderCredentialRecord.CredentialAttributesValues.Count() == 2); var issuerCredRecord = await credentialService.GetAsync(issuer.Context, issuerCredentialRecord.Id); var holderCredRecord = await credentialService.GetAsync(holder.Context, holderCredentialRecord.Id); Assert.Equal(CredentialState.Issued, issuerCredRecord.State); Assert.Equal(CredentialState.Issued, holderCredRecord.State); Assert.Equal( issuerCredRecord.GetTag(TagConstants.LastThreadId), holderCredRecord.GetTag(TagConstants.LastThreadId)); }
public void testGetObjectsAt() { XYLocation loc = new XYLocation(5, 7); env.moveObjectToAbsoluteLocation(a, loc); Assert.assertEquals(1, env.getObjectsAt(loc).size()); AbstractAgent b = new MockAgent(); env.addObjectToLocation(b, loc); Assert.assertEquals(2, env.getObjectsAt(loc).size()); }
private static async Task RunMainAsync() { var client = await StartClientWithRetries(); var grain = client.GetGrain <IAgentRegistryGrain>(0); //var agentId = Guid.NewGuid().ToString(); var agentId = Guid.Parse("253717bf-34b4-43fc-8129-4c68a6bbe1fe").ToString(); MockAgent egg = new MockAgent() { Id = agentId, EggData = Encoding.ASCII.GetBytes("Agent1") }; await grain.AgentStart(egg); var agentsList = await grain.GetAllAgents(); const int port = 50051; const string host = "localhost"; var server = new Server() { Services = { Scynet.Component.BindService(new ComponentFacade(client)) }, Ports = { new ServerPort(host, port, ServerCredentials.Insecure) } }; Console.WriteLine("Starting facade..."); server.Start(); Console.WriteLine("Facade started"); //hatchery channel Channel channel = new Channel("127.0.0.1:9998", ChannelCredentials.Insecure); var hatcheryClient = new Scynet.Hatchery.HatcheryClient(channel); //var componentId = Guid.NewGuid().ToString(); var componentId = Guid.Parse("7730a43f-42a7-49db-b569-50e04929c4f9").ToString(); ComponentRegisterRequest hatcheryComponentRegisterRequest = new ComponentRegisterRequest() { Uuid = componentId, Address = host + ":" + port, }; //add await hatcheryClient.RegisterComponent(hatcheryComponentRegisterRequest); Agent agent = new Agent() { Uuid = agentId, ComponentId = componentId, EggData = ByteString.CopyFrom("Agent1", Encoding.Unicode) }; AgentRegisterRequest arr = new AgentRegisterRequest(); arr.Agent = agent; hatcheryClient.RegisterAgent(arr); await server.ShutdownAsync(); }
public void testGetObjectsNear() { XYLocation loc = new XYLocation(5, 5); env.moveObjectToAbsoluteLocation(a, loc); AbstractAgent b = new MockAgent(); AbstractAgent c = new MockAgent(); Wall w1 = new Wall(); env.addObjectToLocation(b, new XYLocation(7, 4)); env.addObjectToLocation(c, new XYLocation(5, 7)); env.addObjectToLocation(w1, new XYLocation(3, 10)); // at this point agent A should be able to see B and C but not the wall // with a "vision radius" of 3 Set<EnvironmentObject> visibleToA = env.getObjectsNear(a, 3); Assert.assertEquals(2, visibleToA.size()); // agent B should be able to see A only Set<EnvironmentObject> visibleToB = env.getObjectsNear(b, 3); Assert.assertEquals(1, visibleToB.size()); // move B South env.moveObject(b, XYLocation.Direction.South); // at this point both a and c should be visible to b visibleToB = env.getObjectsNear(b, 3); Assert.assertEquals(2, visibleToB.size()); // move c near the wall env.moveObjectToAbsoluteLocation(c, new XYLocation(3, 11)); // only the wall should be visible Set<EnvironmentObject> visibleToC = env.getObjectsNear(c, 3); Assert.assertEquals(1, visibleToC.size()); }
public static async Task <(ConnectionRecord inviteeConnection, ConnectionRecord inviterConnection)> EstablishConnectionWithReturnRoutingAsync(MockAgent invitee, MockAgent inviter, bool useDidKeyFormat = false) { var slim = new SemaphoreSlim(0, 1); var connectionService = inviter.GetService <IConnectionService>(); var messageService = inviter.GetService <IMessageService>(); // Hook into response message event of second runtime to release semaphore invitee.GetService <IEventAggregator>().GetEventByType <ServiceMessageProcessingEvent>() .Where(x => x.MessageType == MessageTypes.ConnectionResponse) .Subscribe(x => slim.Release()); var(invitation, inviteeConnection) = await connectionService.CreateInvitationAsync(inviter.Context, new InviteConfiguration { AutoAcceptConnection = true, UseDidKeyFormat = useDidKeyFormat }); var(request, inviterConnection) = await connectionService.CreateRequestAsync(invitee.Context, invitation); var response = await messageService.SendReceiveAsync <ConnectionResponseMessage>(invitee.Context, request, inviterConnection); Assert.NotNull(response); await connectionService.ProcessResponseAsync(invitee.Context, response, inviterConnection); await slim.WaitAsync(TimeSpan.FromSeconds(30)); var ackMessage = await connectionService.CreateAcknowledgementMessageAsync(invitee.Context, inviterConnection.Id); await messageService.SendAsync(invitee.Context, ackMessage, inviterConnection); await slim.WaitAsync(TimeSpan.FromSeconds(30)); var inviteeConnectionRecord = await connectionService.GetAsync(inviter.Context, inviteeConnection.Id); var inviterConnectionRecord = await connectionService.GetAsync(invitee.Context, inviterConnection.Id); Assert.Equal(ConnectionState.Connected, inviteeConnectionRecord.State); Assert.Equal(ConnectionState.Connected, inviterConnectionRecord.State); Assert.Equal(inviteeConnectionRecord.MyDid, inviterConnectionRecord.TheirDid); Assert.Equal(inviteeConnectionRecord.TheirDid, inviterConnectionRecord.MyDid); Assert.Equal( inviteeConnectionRecord.GetTag(TagConstants.LastThreadId), inviterConnectionRecord.GetTag(TagConstants.LastThreadId)); return(inviteeConnectionRecord, inviterConnectionRecord); }
public static async Task <DiscoveryDiscloseMessage> DiscoveryProtocolWithReturnRoutingAsync(MockAgent requestor, MockAgent holder, ConnectionRecord requestorConnection, ConnectionRecord holderConnection) { var discoveryService = requestor.GetService <IDiscoveryService>(); var messageService = requestor.GetService <IMessageService>(); //Ask for all protocols var msg = discoveryService.CreateQuery(requestor.Context, "*"); var rsp = await messageService.SendAsync(requestor.Context.Wallet, msg, requestorConnection, null, true); Assert.NotNull(rsp); var discoveryMsg = rsp.GetMessage <DiscoveryDiscloseMessage>(); Assert.NotNull(discoveryMsg); return(discoveryMsg); }
public static async Task <DiscoveryDiscloseMessage> DiscoveryProtocolWithReturnRoutingAsync(MockAgent requestor, MockAgent holder, ConnectionRecord requestorConnection, ConnectionRecord holderConnection) { var discoveryService = requestor.GetService <IDiscoveryService>(); var messageService = requestor.GetService <IMessageService>(); //Ask for all protocols var msg = discoveryService.CreateQuery(requestor.Context, "*"); var rsp = await messageService.SendReceiveAsync(requestor.Context, msg, requestorConnection); Assert.NotNull(rsp); if (rsp is UnpackedMessageContext messageContext) { var discoveryMsg = messageContext.GetMessage <DiscoveryDiscloseMessage>(); Assert.NotNull(discoveryMsg); return(discoveryMsg); } throw new InvalidOperationException("The response was not of the expected type"); }
public static async Task <(ConnectionRecord inviteeConnection, ConnectionRecord inviterConnection)> EstablishConnectionWithReturnRoutingAsync(MockAgent invitee, MockAgent inviter) { var slim = new SemaphoreSlim(0, 1); var connectionService = invitee.GetService <IConnectionService>(); var messsageService = invitee.GetService <IMessageService>(); // Hook into response message event of second runtime to release semaphore inviter.GetService <IEventAggregator>().GetEventByType <ServiceMessageProcessingEvent>() .Where(x => x.MessageType == MessageTypes.ConnectionResponse) .Subscribe(x => slim.Release()); (var invitation, var inviterConnection) = await connectionService.CreateInvitationAsync(invitee.Context, new InviteConfiguration { AutoAcceptConnection = true }); (var request, var inviteeConnection) = await connectionService.CreateRequestAsync(inviter.Context, invitation); var response = await messsageService.SendAsync(inviter.Context.Wallet, request, inviteeConnection, invitation.RecipientKeys.First(), true); Assert.NotNull(response); await inviter.HandleInboundAsync(response); await slim.WaitAsync(TimeSpan.FromSeconds(30)); var connectionRecord1 = await connectionService.GetAsync(invitee.Context, inviterConnection.Id); var connectionRecord2 = await connectionService.GetAsync(inviter.Context, inviteeConnection.Id); Assert.Equal(ConnectionState.Connected, connectionRecord1.State); Assert.Equal(ConnectionState.Connected, connectionRecord2.State); Assert.Equal(connectionRecord1.MyDid, connectionRecord2.TheirDid); Assert.Equal(connectionRecord1.TheirDid, connectionRecord2.MyDid); Assert.Equal( connectionRecord1.GetTag(TagConstants.LastThreadId), connectionRecord2.GetTag(TagConstants.LastThreadId)); return(connectionRecord1, connectionRecord2); }
public static async Task <(ConnectionRecord inviteeConnection, ConnectionRecord inviterConnection)> EstablishConnectionAsync(MockAgent invitee, MockAgent inviter, bool useDidKeyFormat = false) { var slim = new SemaphoreSlim(0, 1); var connectionService = invitee.GetService <IConnectionService>(); var messageService = invitee.GetService <IMessageService>(); // Hook into response message event of second runtime to release semaphore inviter.GetService <IEventAggregator>().GetEventByType <ServiceMessageProcessingEvent>() .Where(x => x.MessageType == MessageTypes.ConnectionResponse) .Subscribe(x => slim.Release()); (var invitation, var inviterConnection) = await connectionService.CreateInvitationAsync(invitee.Context, new InviteConfiguration { AutoAcceptConnection = true, UseDidKeyFormat = useDidKeyFormat }); var(request, inviteeConnection) = await connectionService.CreateRequestAsync(inviter.Context, invitation); await messageService.SendAsync(inviter.Context, request, inviteeConnection); // Wait for connection to be established or continue after 30 sec timeout await slim.WaitAsync(TimeSpan.FromSeconds(30)); var connectionRecord1 = await connectionService.GetAsync(invitee.Context, inviterConnection.Id); var connectionRecord2 = await connectionService.GetAsync(inviter.Context, inviteeConnection.Id); Assert.Equal(ConnectionState.Connected, connectionRecord1.State); Assert.Equal(ConnectionState.Connected, connectionRecord2.State); Assert.Equal(connectionRecord1.MyDid, connectionRecord2.TheirDid); Assert.Equal(connectionRecord1.TheirDid, connectionRecord2.MyDid); Assert.Equal( connectionRecord1.GetTag(TagConstants.LastThreadId), connectionRecord2.GetTag(TagConstants.LastThreadId)); return(connectionRecord1, connectionRecord2); }
public static async Task IssueCredentialAsync(MockAgent issuer, MockAgent holder, ConnectionRecord issuerConnection, ConnectionRecord holderConnection, List <CredentialPreviewAttribute> credentialAttributes) { var credentialService = issuer.GetService <ICredentialService>(); var messageService = issuer.GetService <IMessageService>(); var schemaService = issuer.GetService <ISchemaService>(); var provisionService = issuer.GetService <IProvisioningService>(); // Hook into message event var offerSlim = new SemaphoreSlim(0, 1); holder.GetService <IEventAggregator>().GetEventByType <ServiceMessageProcessingEvent>() .Where(x => x.MessageType == MessageTypes.IssueCredentialNames.OfferCredential) .Subscribe(x => offerSlim.Release()); var issuerProv = await provisionService.GetProvisioningAsync(issuer.Context.Wallet); var(definitionId, _) = await Scenarios.CreateDummySchemaAndNonRevokableCredDef(issuer.Context, schemaService, issuerProv.IssuerDid, credentialAttributes.Select(_ => _.Name).ToArray()); var(offer, issuerCredentialRecord) = await credentialService.CreateOfferAsync( agentContext : issuer.Context, config : new OfferConfiguration { IssuerDid = issuerProv.IssuerDid, CredentialDefinitionId = definitionId, CredentialAttributeValues = credentialAttributes, }, connectionId : issuerConnection.Id); await messageService.SendAsync(issuer.Context, offer, issuerConnection); await offerSlim.WaitAsync(TimeSpan.FromSeconds(30)); var offers = await credentialService.ListOffersAsync(holder.Context); Assert.NotNull(offers); Assert.True(offers.Count > 0); // Hook into message event var requestSlim = new SemaphoreSlim(0, 1); issuer.GetService <IEventAggregator>().GetEventByType <ServiceMessageProcessingEvent>() .Where(x => x.MessageType == MessageTypes.IssueCredentialNames.RequestCredential) .Subscribe(x => requestSlim.Release()); var(request, holderCredentialRecord) = await credentialService.CreateRequestAsync(holder.Context, offers[0].Id); Assert.NotNull(holderCredentialRecord.CredentialAttributesValues); Assert.True(holderCredentialRecord.CredentialAttributesValues.Count() == 2); await messageService.SendAsync(holder.Context, request, holderConnection); await requestSlim.WaitAsync(TimeSpan.FromSeconds(30)); // Hook into message event var credentialSlim = new SemaphoreSlim(0, 1); holder.GetService <IEventAggregator>().GetEventByType <ServiceMessageProcessingEvent>() .Where(x => x.MessageType == MessageTypes.IssueCredentialNames.IssueCredential) .Subscribe(x => credentialSlim.Release()); var(cred, _) = await credentialService.CreateCredentialAsync( agentContext : issuer.Context, credentialId : issuerCredentialRecord.Id); await messageService.SendAsync(issuer.Context, cred, issuerConnection); await credentialSlim.WaitAsync(TimeSpan.FromSeconds(30)); var issuerCredRecord = await credentialService.GetAsync(issuer.Context, issuerCredentialRecord.Id); var holderCredRecord = await credentialService.GetAsync(holder.Context, holderCredentialRecord.Id); Assert.Equal(CredentialState.Issued, issuerCredRecord.State); Assert.Equal(CredentialState.Issued, holderCredRecord.State); Assert.Equal( issuerCredRecord.GetTag(TagConstants.LastThreadId), holderCredRecord.GetTag(TagConstants.LastThreadId)); var ackSlim = new SemaphoreSlim(0, 1); holder.GetService <IEventAggregator>().GetEventByType <ServiceMessageProcessingEvent>() .Where(x => x.MessageType == MessageTypes.IssueCredentialNames.AcknowledgeCredential) .Subscribe(x => ackSlim.Release()); var ackMessage = await credentialService.CreateAcknowledgementMessageAsync(holder.Context, holderCredentialRecord.Id); await messageService.SendAsync(holder.Context, ackMessage, holderConnection); await ackSlim.WaitAsync(TimeSpan.FromSeconds(30)); Assert.Equal(ackMessage.Id, issuerCredRecord.GetTag(TagConstants.LastThreadId)); }