Esempio n. 1
0
 public CryptographerTests()
 {
     m_tester = AgentTester.CreateTest();
     m_cryptographer = m_tester.AgentA.Cryptographer;
     MemoryX509Store certs = AgentTester.LoadPrivateCerts("redmond");
     m_cert = certs.First();
 }
Esempio n. 2
0
        public void B240_GetAccounts_NotIsOwned()
        {
            var v = AgentTester.Test <AccountAgent, AccountCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetAccountsAsync(new AccountArgs {
                IsOwned = false
            })).Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(1, v.Result.Count);
            Assert.AreEqual(new string[] { "45678901" }, v.Result.Select(x => x.Id).ToArray());
        }
Esempio n. 3
0
        public void A220_GetByArgs_FirstName()
        {
            var v = AgentTester.Test <PersonAgent, PersonCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetByArgsAsync(new PersonArgs {
                FirstName = "*a*"
            })).Value !;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(3, v.Result.Count);
            Assert.AreEqual(new string[] { "Browne", "Smith", "Smithers" }, v.Result.Select(x => x.LastName).ToArray());
        }
Esempio n. 4
0
        public void OneTimeSetUp()
        {
            TestSetUp.RegisterSetUp(async(count, _) =>
            {
                return(await DatabaseExecutor.RunAsync(
                           count == 0 ? DatabaseExecutorCommand.ResetAndDatabase : DatabaseExecutorCommand.ResetAndData,
                           AgentTester.Configuration["ConnectionStrings:Database"], useBeefDbo: true,
                           typeof(Database.Program).Assembly, Assembly.GetExecutingAssembly()).ConfigureAwait(false) == 0);
            });

            AgentTester.TestServerStart <Startup>("AppName");
            AgentTester.DefaultExpectNoEvents = true;
        }
Esempio n. 5
0
        public void B140_GetTransactions_MaxAmount()
        {
            var v = AgentTester.Test <TransactionAgent, TransactionCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetTransactionsAsync("12345678", new TransactionArgs {
                FromDate = new DateTime(2019, 04, 01), MaxAmount = 0
            })).Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(2, v.Result.Count);
            Assert.AreEqual(new string[] { "X0007", "X0001" }, v.Result.Select(x => x.Id).ToArray());
        }
Esempio n. 6
0
        public void B210_GetAccounts_OpenStatus()
        {
            var v = AgentTester.Test <AccountAgent, AccountCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetAccountsAsync(new AccountArgs {
                OpenStatus = "OPEN"
            })).Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(2, v.Result.Count);
            Assert.AreEqual(new string[] { "12345678", "34567890" }, v.Result.Select(x => x.Id).ToArray());
        }
Esempio n. 7
0
        public void B220_GetAccounts_ProductCategory()
        {
            var v = AgentTester.Create <AccountAgent, AccountCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetAccountsAsync(new AccountArgs {
                ProductCategory = "CRED_AND_CHRG_CARDS"
            })).Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(1, v.Result.Count);
            Assert.AreEqual(new string[] { "34567890" }, v.Result.Select(x => x.Id).ToArray());
        }
Esempio n. 8
0
        public void OneTimeSetUp()
        {
            var config = AgentTester.BuildConfiguration <Startup>("Beef");

            TestSetUp.SetDefaultLocalReferenceData <IReferenceData, ReferenceDataAgentProvider, IReferenceDataAgent, ReferenceDataAgent>();
            TestSetUp.RegisterSetUp(async(count, data) =>
            {
                return(await DatabaseExecutor.RunAsync(
                           count == 0 ? DatabaseExecutorCommand.ResetAndDatabase : DatabaseExecutorCommand.ResetAndData,
                           config["ConnectionStrings:BeefDemo"], useBeefDbo: true,
                           typeof(Database.Program).Assembly, Assembly.GetExecutingAssembly(), typeof(Beef.Demo.Abc.Database.Scripts).Assembly).ConfigureAwait(false) == 0);
            });
        }
Esempio n. 9
0
        public void B230_GetAccounts_IsOwned()
        {
            var v = AgentTester.Create <AccountAgent, AccountCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetAccountsAsync(new AccountArgs {
                IsOwned = true
            })).Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(2, v.Result.Count);
            Assert.AreEqual(new string[] { "12345678", "34567890" }, v.Result.Select(x => x.Id).ToArray());
        }
Esempio n. 10
0
        public void A150_Get_IncludeRefDataText()
        {
            using var agentTester = AgentTester.CreateWaf <Startup>();

            var v = agentTester.Test <EmployeeAgent, Employee?>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetAsync(1.ToGuid(), new WebApiRequestOptions {
                IncludeRefDataText = true
            })).Value !;

            Assert.NotNull(v);
            Assert.AreEqual("Female", v.GenderText);
        }
Esempio n. 11
0
        public void F110_Update_NotFound()
        {
            // Get an existing Robot.
            var v = AgentTester.Create <RobotAgent, Robot>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetAsync(1.ToGuid())).Value;

            // Update with an invalid identifier.
            AgentTester.Create <RobotAgent, Robot>()
            .ExpectStatusCode(HttpStatusCode.NotFound)
            .ExpectErrorType(ErrorType.NotFoundError)
            .Run((a) => a.Agent.UpdateAsync(v, 404.ToGuid()));
        }
Esempio n. 12
0
        public void OneTimeSetUp()
        {
            TestSetUp.RegisterSetUp((count, data) =>
            {
                return(DatabaseExecutor.Run(
                           count == 0 ? DatabaseExecutorCommand.ResetAndDatabase : DatabaseExecutorCommand.ResetAndData,
                           AgentTester.Configuration["ConnectionStrings:Database"],
                           typeof(DatabaseExecutor).Assembly, typeof(Database.Program).Assembly, Assembly.GetExecutingAssembly()) == 0);
            });

            AgentTester.StartupTestServer <Startup>(environmentVariablesPrefix: "AppName_");
            AgentTester.DefaultExpectNoEvents = true;
        }
Esempio n. 13
0
        public void B150_GetTransactions_Text()
        {
            var v = AgentTester.Create <TransactionAgent, TransactionCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetTransactionsAsync("23456789", new TransactionArgs {
                FromDate = new DateTime(2019, 04, 01), Text = "usb"
            })).Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(2, v.Result.Count);
            Assert.AreEqual(new string[] { "X0006", "X0002" }, v.Result.Select(x => x.Id).ToArray());
        }
Esempio n. 14
0
        public void E110_Patch_NotFound()
        {
            // Get an existing value.
            var v = AgentTester.Create <PersonAgent, Person>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetAsync(2.ToGuid())).Value;

            // Try patching with an invalid identifier.
            AgentTester.Create <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.NotFound)
            .ExpectErrorType(ErrorType.NotFoundError)
            .Run((a) => a.Agent.PatchAsync(WebApiPatchOption.MergePatch, "{ \"lastName\": \"Smithers\" }", 404.ToGuid()));
        }
Esempio n. 15
0
        public void D110_Update_NotFound()
        {
            // Get an existing value.
            var v = AgentTester.Create <PersonAgent, Person>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetAsync(2.ToGuid())).Value;

            // Try updating with an invalid identifier.
            AgentTester.Create <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.NotFound)
            .ExpectErrorType(ErrorType.NotFoundError)
            .Run((a) => a.Agent.UpdateAsync(v, 404.ToGuid()));
        }
Esempio n. 16
0
        public void B230_GetByArgs_LastName()
        {
            var v = AgentTester.Create <PersonAgent, PersonCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetByArgsAsync(new PersonArgs {
                LastName = "s*"
            })).Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(2, v.Result.Count);
            Assert.AreEqual(new string[] { "Smith", "Smithers" }, v.Result.Select(x => x.LastName).ToArray());
        }
Esempio n. 17
0
        public void A210_GetByArgs_All()
        {
            using var agentTester = AgentTester.CreateWaf <Startup>();

            var v = agentTester.Test <EmployeeAgent, EmployeeBaseCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetByArgsAsync(null)).Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(3, v.Result.Count);
            Assert.AreEqual(new string[] { "Browne", "Jones", "Smithers" }, v.Result.Select(x => x.LastName).ToArray());
        }
Esempio n. 18
0
 public void I140_Map()
 {
     AgentTester.Create <PersonAgent, MapCoordinates>()
     .ExpectStatusCode(HttpStatusCode.OK)
     .ExpectValue(_ => new MapCoordinates {
         Longitude = 1.234m, Latitude = -6.789m
     })
     .Run((a) => a.Agent.MapAsync(new MapArgs {
         Coordinates = new MapCoordinates {
             Longitude = 1.234m, Latitude = -6.789m
         }
     }));
 }
Esempio n. 19
0
        public void A220_GetByEmployeeId_Last()
        {
            using var agentTester = AgentTester.CreateWaf <Startup>();

            var v = agentTester.Test <PerformanceReviewAgent, PerformanceReviewCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetByEmployeeIdAsync(2.ToGuid(), PagingArgs.CreateSkipAndTake(0, 1))).Value !;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(1, v.Result.Count);
            Assert.AreEqual(new string[] { "Work quality low." }, v.Result.Select(x => x.Notes).ToArray());
        }
Esempio n. 20
0
        public void C150_GetByArgs_All_NoResult()
        {
            var rcr = AgentTester.TestGrpc <RobotAgent, RobotCollectionResult>()
                      .ExpectStatusCode(HttpStatusCode.OK)
                      .Run(a => a.GetByArgsAsync(new RobotArgs {
                ModelNo = "ABC", SerialNo = "K*", PowerSources = new RefData.ReferenceDataSidList <PowerSource, string> {
                    "F", "N"
                }
            }));

            // Check nothing is returned..
            Assert.AreEqual(0, rcr?.Value?.Result?.Count);
        }
Esempio n. 21
0
        public void F210_UpdateWithEF_NotFound()
        {
            // Get an existing person.
            var p = AgentTester.Create <PersonAgent, Person>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetAsync(1.ToGuid())).Value;

            // Update with an invalid identifier.
            AgentTester.Create <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.NotFound)
            .ExpectErrorType(ErrorType.NotFoundError)
            .Run((a) => a.Agent.UpdateWithEfAsync(p, 404.ToGuid()));
        }
Esempio n. 22
0
        private void GetByArgs_EmptyArgs(bool useEf)
        {
            // Test with null args.
            var args = new PersonArgs {
            };
            var pcr  = AgentTester.Create <PersonAgent, PersonCollectionResult>()
                       .ExpectStatusCode(HttpStatusCode.OK)
                       .Run((a) => useEf ? a.Agent.GetByArgsWithEfAsync(args) : a.Agent.GetByArgsAsync(args));

            // Check all 4 are returned in the sorted order.
            Assert.AreEqual(4, pcr?.Value?.Result?.Count);
            Assert.AreEqual(new string[] { "Browne", "Jones", "Smith", "Smithers" }, pcr.Value.Result.Select(x => x.LastName).ToArray());
        }
Esempio n. 23
0
 public void B320_GetWithEf_Found_With_Address()
 {
     AgentTester.Create <PersonAgent, Person>()
     .ExpectStatusCode(HttpStatusCode.OK)
     .IgnoreChangeLog()
     .IgnoreETag()
     .ExpectValue((t) => new Person {
         Id = 3.ToGuid(), FirstName = "Rachael", LastName = "Browne", Gender = "F", Birthday = new DateTime(1972, 06, 28), Address = new Address {
             Street = "25 Upoko Road", City = "Wellington"
         }
     })
     .Run((a) => a.Agent.GetWithEfAsync(3.ToGuid()));
 }
Esempio n. 24
0
 public void B120_Get_Found_WithText()
 {
     AgentTester.Test <RobotAgent, Robot>()
     .ExpectStatusCode(HttpStatusCode.OK)
     .IgnoreChangeLog()
     .IgnoreETag()
     .ExpectValue((t) => new Robot {
         Id = 1.ToGuid(), ModelNo = "T1000", SerialNo = "123456", PowerSource = "F", PowerSourceText = "Fusion"
     })
     .Run(a => a.GetAsync(1.ToGuid(), new Beef.WebApi.WebApiRequestOptions {
         UrlQueryString = "$text=true"
     }));
 }
Esempio n. 25
0
        public void TestSoft_To_HSM_DecryptException_NoCerts()
        {
            var resolverSettings = MockTokenResolverSettings(TokenSettings);

            // Hardware Cryptographer Agent

            using (var hsmCryptographer = new HsmCryptographerProxy())
            {
                hsmCryptographer.Init(resolverSettings);

                var diagnostics = new FakeDiagnostics(typeof(HsmCryptographerProxy));
                hsmCryptographer.Error   += diagnostics.OnResolverError;
                hsmCryptographer.Warning += diagnostics.OnResolverWarning;

                var agentB = AgentTester.CreateAgent(
                    "hsm.DirectInt.lab",
                    AgentTester.MakeCertificatesPath(Directory.GetCurrentDirectory(), "nhind"),
                    hsmCryptographer);

                // Software Cryptographer Agent

                var agentA = AgentTester.CreateAgent(
                    AgentTester.DefaultDomainA,
                    AgentTester.MakeCertificatesPath(Directory.GetCurrentDirectory(), "redmond"),
                    //new TestSmimeCryptographer(EncryptionAlgorithm.AES128, DigestAlgorithm.SHA256));
                    SMIMECryptographer.Default);

                var tester = new AgentTester(agentA, agentB);

                string messageText = tester.ReadMessageText("simpleSoftToHsm.eml");
                var    message     = MimeSerializer.Default.Deserialize <Message>(messageText);

                var encryptedEntity = tester.AgentA.Cryptographer.Encrypt(message, m_singleUseSigningPublicCert);

                // Decrypt with first resolved local cert (hardware cert) but is wrong

                var decryptedEntity = tester.AgentB.Cryptographer
                                      .DecryptEntity(
                    hsmCryptographer.GetEncryptedBytes(encryptedEntity),
                    null);

                Assert.Null(decryptedEntity);

                Assert.Equal(0, diagnostics.ActualWarningMessages.Count);
                Assert.Equal(1, diagnostics.ActualErrorMessages.Count);

                Assert.Equal(
                    "Error occurred during a cryptographic operation.",
                    diagnostics.ActualErrorMessages[0]);
            }
        }
Esempio n. 26
0
        public void A250_GetByArgs_Empty()
        {
            var v = AgentTester.Test <EmployeeAgent, EmployeeBaseCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetByArgsAsync(new EmployeeArgs {
                LastName = "s*", FirstName = "b*", GendersSids = new List <string> {
                    "F"
                }
            })).Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(0, v.Result.Count);
        }
Esempio n. 27
0
        public void D110_Patch_NotFound()
        {
            using var agentTester = AgentTester.CreateWaf <Startup>();

            // Get an existing value.
            var v = agentTester.Test <PersonAgent, Person?>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetAsync(2.ToGuid())).Value !;

            // Try patching with an invalid identifier.
            agentTester.Test <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.NotFound)
            .Run(a => a.PatchAsync(WebApiPatchOption.MergePatch, "{ \"lastName\": \"Smithers\" }", 404.ToGuid()));
        }
Esempio n. 28
0
        public void C110_Update_NotFound()
        {
            using var agentTester = AgentTester.CreateWaf <Startup>();

            // Get an existing value.
            var v = agentTester.Test <PersonAgent, Person?>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetAsync(2.ToGuid())).Value !;

            // Try updating with an invalid identifier.
            agentTester.Test <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.NotFound)
            .Run(a => a.UpdateAsync(v, 404.ToGuid()));
        }
Esempio n. 29
0
        public void B250_GetByArgs_Empty()
        {
            var v = AgentTester.Create <PersonAgent, PersonCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetByArgsAsync(new PersonArgs {
                LastName = "s*", FirstName = "b*", GendersSids = new List <string> {
                    "F"
                }
            })).Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(0, v.Result.Count);
        }
Esempio n. 30
0
        public void A210_RaiseEvent_EventOutboxSuccess()
        {
            using var agentTester = AgentTester.CreateWaf <Startup>();

            var r = agentTester.Test <ContactAgent>()
                    .ExpectStatusCode(HttpStatusCode.NoContent)
                    .ExpectEvent("Contact", "Made")
                    .Run(a => a.RaiseEventAsync(false));

            var db    = new Beef.Demo.Business.Data.Database(agentTester.WebApplicationFactory.Services.GetService <IConfiguration>()["ConnectionStrings:BeefDemo"]);
            var count = db.SqlStatement("SELECT COUNT(*) FROM [Demo].[EventOutboxData] WHERE [Subject] = 'Contact' and [Action] = 'Made'").ScalarAsync <int>().GetAwaiter().GetResult();

            Assert.AreEqual(1, count);
        }
Esempio n. 31
0
        public void A160_GetPowerSource_FilterByCodes()
        {
            var r = AgentTester.Create <ReferenceDataAgent, PowerSourceCollection>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.PowerSourceGetAllAsync(new RefData.ReferenceDataFilter {
                Codes = new List <string> {
                    "E", null, "n"
                }
            }));

            Assert.IsNotNull(r);
            Assert.IsNotNull(r.Value);
            Assert.AreEqual(2, r.Value.Count());
        }
Esempio n. 32
0
 public BasicAgentTests()
 {
     m_tester = AgentTester.CreateTest();
 }