private MockMessage CreateAsynchronousMessageProtected() { var certificateStore = new MockCertificateStore(); var messageProtection = new SignThenEncryptMessageProtection(TestCertificates.HelsenorgePrivateSigntature, TestCertificates.HelsenorgePrivateEncryption); var messageId = Guid.NewGuid().ToString("D"); var path = Path.Combine("Files", "Helsenorge_Message.xml"); var file = File.Exists(path) ? new XDocument(XElement.Load(path)) : null; var protect = messageProtection.Protect(file == null ? GenericMessage.ToStream() : file.ToStream(), TestCertificates.HelsenorgePublicEncryption); return(new MockMessage(protect) { MessageFunction = "DIALOG_INNBYGGER_EKONTAKT", ApplicationTimestamp = DateTime.Now, ContentType = ContentType.SignedAndEnveloped, MessageId = messageId, CorrelationId = messageId, FromHerId = MockFactory.OtherHerId, ToHerId = MockFactory.HelsenorgeHerId, ScheduledEnqueueTimeUtc = DateTime.UtcNow, TimeToLive = TimeSpan.FromSeconds(15), ReplyTo = MockFactory.OtherParty.Asynchronous.Name, Queue = MockFactory.Helsenorge.Asynchronous.Messages, }); }
internal void SetupInternal(int otherHerId) { var addressRegistrySettings = new AddressRegistrySettings() { UserName = "******", Password = "******", EndpointName = "SomeEndpointName", WcfConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None), CachingInterval = TimeSpan.FromSeconds(5) }; var collaborationRegistrySettings = new CollaborationProtocolRegistrySettings() { UserName = "******", Password = "******", EndpointName = "SomeEndpointName", WcfConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None), CachingInterval = TimeSpan.FromSeconds(5) }; LoggerFactory = new LoggerFactory(); MockLoggerProvider = new MockLoggerProvider(null); LoggerFactory.AddProvider(MockLoggerProvider); Logger = LoggerFactory.CreateLogger <BaseTest>(); var distributedCache = DistributedCacheFactory.Create(); AddressRegistry = new AddressRegistryMock(addressRegistrySettings, distributedCache); AddressRegistry.SetupFindCommunicationPartyDetails(i => { var file = Path.Combine("Files", $"CommunicationDetails_{i}.xml"); return(File.Exists(file) == false ? null : XElement.Load(file)); }); AddressRegistry.SetupGetCertificateDetailsForEncryption(i => { var path = Path.Combine("Files", $"GetCertificateDetailsForEncryption_{i}.xml"); return(File.Exists(path) == false ? null : XElement.Load(path)); }); AddressRegistry.SetupGetCertificateDetailsForValidatingSignature(i => { var path = Path.Combine("Files", $"GetCertificateDetailsForValidatingSignature_{i}.xml"); return(File.Exists(path) == false ? null : XElement.Load(path)); }); CollaborationRegistry = new CollaborationProtocolRegistryMock(collaborationRegistrySettings, distributedCache, AddressRegistry); CollaborationRegistry.SetupFindProtocolForCounterparty(i => { var file = Path.Combine("Files", $"CPP_{i}.xml"); return(File.Exists(file) == false ? null : File.ReadAllText(file)); }); CollaborationRegistry.SetupFindAgreementForCounterparty(i => { var file = Path.Combine("Files", $"CPA_{i}.xml"); return(File.Exists(file) == false ? null : File.ReadAllText(file)); }); CollaborationRegistry.SetupFindAgreementById(i => { var file = Path.Combine("Files", $"CPA_{i:D}.xml"); return(File.Exists(file) == false ? null : File.ReadAllText(file)); }); Settings = new MessagingSettings() { MyHerId = MockFactory.HelsenorgeHerId, SigningCertificate = new CertificateSettings() { StoreName = StoreName.My, StoreLocation = StoreLocation.LocalMachine, Thumbprint = TestCertificates.HelsenorgeSigntatureThumbprint }, DecryptionCertificate = new CertificateSettings() { StoreName = StoreName.My, StoreLocation = StoreLocation.LocalMachine, Thumbprint = TestCertificates.HelsenorgeEncryptionThumbprint } }; Settings.ServiceBus.ConnectionString = "connection string"; Settings.ServiceBus.Synchronous.ReplyQueueMapping.Add(Environment.MachineName.ToLower(), "RepliesGoHere"); // make things easier by only having one processing task per queue Settings.ServiceBus.Asynchronous.ProcessingTasks = 1; Settings.ServiceBus.Synchronous.ProcessingTasks = 1; Settings.ServiceBus.Error.ProcessingTasks = 1; MockFactory = new MockFactory(otherHerId); CertificateValidator = new MockCertificateValidator(); CertificateStore = new MockCertificateStore(); var signingCertificate = CertificateStore.GetCertificate(TestCertificates.HelsenorgeSigntatureThumbprint); var encryptionCertificate = CertificateStore.GetCertificate(TestCertificates.HelsenorgeEncryptionThumbprint); MessageProtection = new MockMessageProtection(signingCertificate, encryptionCertificate); Client = new MessagingClient( Settings, CollaborationRegistry, AddressRegistry, CertificateStore, CertificateValidator, MessageProtection ); Client.ServiceBus.RegisterAlternateMessagingFactory(MockFactory); Server = new MessagingServer( Settings, LoggerFactory, CollaborationRegistry, AddressRegistry, CertificateStore, CertificateValidator, MessageProtection ); Server.ServiceBus.RegisterAlternateMessagingFactory(MockFactory); }