Exemple #1
0
        public void H140_Patch_JsonPatch()
        {
            // Get an existing person.
            var p = AgentTester.Test <PersonAgent, Person>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetAsync(3.ToGuid())).Value;

            p.LastName = "Simons";

            // Try patching the person with an invalid eTag.
            p = AgentTester.Test <PersonAgent, Person>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .ExpectETag(p.ETag)
                .ExpectChangeLogUpdated()
                .ExpectValue(_ => p)
                .Run(a => a.PatchAsync(WebApiPatchOption.JsonPatch,
                                       JToken.Parse("[ { op: \"replace\", \"path\": \"lastName\", \"value\": \"Simons\" } ]"),
                                       3.ToGuid(), new WebApiRequestOptions {
                ETag = p.ETag
            })).Value;

            // Check the person was patched properly.
            AgentTester.Test <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .ExpectValue(_ => p)
            .Run(a => a.GetAsync(3.ToGuid()));
        }
Exemple #2
0
        public void H150_PatchDetail_MergePatch_UniqueKeyCollection()
        {
            // Get an existing person detail.
            var p = AgentTester.Test <PersonAgent, PersonDetail>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetDetailAsync(4.ToGuid())).Value;

            var jt = JToken.Parse(
                "{ \"history\": [ { \"name\": \"Amazon\", \"endDate\": \"2018-04-16T00:00:00\" }, " +
                "{ \"name\": \"Microsoft\" }, " +
                "{ \"name\": \"Google\", \"startDate\": \"2018-04-30T00:00:00\" } ] }");

            p = AgentTester.Test <PersonAgent, PersonDetail>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .Run(a => a.PatchDetailAsync(WebApiPatchOption.MergePatch, jt, 4.ToGuid(), new WebApiRequestOptions {
                ETag = p.ETag
            })).Value;

            Assert.IsNotNull(p);
            Assert.IsNotNull(p.History);
            Assert.AreEqual(3, p.History.Count);

            Assert.AreEqual("Google", p.History[0].Name);
            Assert.AreEqual(new DateTime(2018, 04, 30), p.History[0].StartDate);
            Assert.IsNull(p.History[0].EndDate);

            Assert.AreEqual("Amazon", p.History[1].Name);
            Assert.AreEqual(new DateTime(2016, 04, 16), p.History[1].StartDate);
            Assert.AreEqual(new DateTime(2018, 04, 16), p.History[1].EndDate);

            Assert.AreEqual("Microsoft", p.History[2].Name);
            Assert.AreEqual(new DateTime(2015, 05, 23), p.History[2].StartDate);
            Assert.AreEqual(new DateTime(2016, 04, 06), p.History[2].EndDate);
        }
Exemple #3
0
 public void G210_DeleteWithEf_NotFound()
 {
     // Deleting a person that does not exist only reports success.
     AgentTester.Test <PersonAgent>()
     .ExpectStatusCode(HttpStatusCode.NoContent)
     .Run(a => a.DeleteWithEfAsync(404.ToGuid()));
 }
Exemple #4
0
        public void E110_Delete()
        {
            // Check value exists.
            var id = 4.ToGuid();

            AgentTester.Test <PersonAgent, Person?>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .Run(a => a.GetAsync(id));

            // Delete value.
            AgentTester.Test <PersonAgent>()
            .ExpectStatusCode(HttpStatusCode.NoContent)
            .ExpectEvent($"Company.AppName.Person.{id}", "Deleted")
            .Run(a => a.DeleteAsync(id));

            // Check value no longer exists.
            AgentTester.Test <PersonAgent, Person?>()
            .ExpectStatusCode(HttpStatusCode.NotFound)
            .Run(a => a.GetAsync(id));

            // Delete again (should still be successful as a Delete is idempotent); but no event should be raised.
            AgentTester.Test <PersonAgent>()
            .ExpectStatusCode(HttpStatusCode.NoContent)
            .Run(a => a.DeleteAsync(id));
        }
Exemple #5
0
        public void D130_Patch()
        {
            // Get an existing value.
            var id = 2.ToGuid();
            var v  = AgentTester.Test <PersonAgent, Person?>()
                     .ExpectStatusCode(HttpStatusCode.OK)
                     .Run(a => a.GetAsync(id)).Value !;

            // Make some changes to the data.
            v.LastName = "Smithers";

            // Update the value.
            v = AgentTester.Test <PersonAgent, Person>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .ExpectChangeLogUpdated()
                .ExpectETag(v.ETag)
                .ExpectUniqueKey()
                .ExpectValue(_ => v)
                .ExpectEvent($"Company.AppName.Person.{id}", "Updated")
                .Run(a => a.PatchAsync(WebApiPatchOption.MergePatch, $"{{ \"lastName\": \"{v.LastName}\" }}", id, new WebApiRequestOptions {
                ETag = v.ETag
            })).Value !;

            // Check the value was updated properly.
            AgentTester.Test <PersonAgent, Person?>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .ExpectValue(_ => v)
            .Run(a => a.GetAsync(id));
        }
Exemple #6
0
        public void A175_GetPowerSource_FilterByCodes_Inactive()
        {
            var r = AgentTester.Test <ReferenceDataAgent, PowerSourceCollection>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.PowerSourceGetAllAsync(new RefData.ReferenceDataFilter {
                Codes = new List <string> {
                    "o"
                }
            }));

            Assert.IsNotNull(r);
            Assert.IsNotNull(r.Value);
            Assert.AreEqual(0, r.Value.Count());

            r = AgentTester.Test <ReferenceDataAgent, PowerSourceCollection>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .Run(a => a.PowerSourceGetAllAsync(new RefData.ReferenceDataFilter {
                Codes = new List <string> {
                    "o"
                }
            }, new Beef.WebApi.WebApiRequestOptions {
                UrlQueryString = "$inactive=true"
            }));

            Assert.IsNotNull(r);
            Assert.IsNotNull(r.Value);
            Assert.AreEqual(1, r.Value.Count());
        }
Exemple #7
0
 public void G110_Delete_NotFound()
 {
     // Deleting a Robot that does not exist only reports success.
     AgentTester.Test <RobotAgent>()
     .ExpectStatusCode(HttpStatusCode.NoContent)
     .Run(a => a.DeleteAsync(404.ToGuid()));
 }
Exemple #8
0
        public void B110_Create()
        {
            var v = new Person
            {
                FirstName = "Jill",
                LastName  = "Smith",
                GenderSid = "F",
                Birthday  = new DateTime(1955, 10, 28)
            };

            // Create value.
            v = AgentTester.Test <PersonAgent, Person>()
                .ExpectStatusCode(HttpStatusCode.Created)
                .ExpectChangeLogCreated()
                .ExpectETag()
                .ExpectUniqueKey()
                .ExpectValue(_ => v)
                .ExpectEvent("Company.AppName.Person.*", "Created")
                .Run(a => a.CreateAsync(v)).Value !;

            // Check the value was created properly.
            AgentTester.Test <PersonAgent, Person?>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .ExpectValue(_ => v)
            .Run(a => a.GetAsync(v.Id));
        }
Exemple #9
0
 public void B110_Get_NotFound()
 {
     AgentTester.Test <TripPersonAgent, TripPerson>()
     .ExpectStatusCode(HttpStatusCode.NotFound)
     .ExpectErrorType(Beef.ErrorType.NotFoundError)
     .Run(a => a.GetAsync("rando"));
 }
Exemple #10
0
        public void B230_GetDetail_WithWorkHistory()
        {
            var pd = new PersonDetail
            {
                Id          = 2.ToGuid(),
                FirstName   = "Brian",
                LastName    = "Smith",
                GenderSid   = "M",
                EyeColorSid = "BLUE",
                UniqueCode  = "B2345",
                Birthday    = new DateTime(1994, 11, 07),
                History     = new WorkHistoryCollection {
                    new WorkHistory {
                        Name = "Optus", StartDate = new DateTime(2016, 04, 16)
                    },
                    new WorkHistory {
                        Name = "Telstra", StartDate = new DateTime(2015, 05, 23), EndDate = new DateTime(2016, 04, 06)
                    }
                }
            };

            AgentTester.Test <PersonAgent, PersonDetail>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .IgnoreChangeLog()
            .IgnoreETag()
            .ExpectValue((t) => pd)
            .Run(a => a.GetDetailAsync(2.ToGuid()));
        }
Exemple #11
0
        public void E210_CreateWithEf()
        {
            var p = new Person
            {
                FirstName  = "Bill",
                LastName   = "Gates",
                GenderSid  = "M",
                Birthday   = new DateTime(1955, 10, 28),
                UniqueCode = "C5678"
            };

            // Create a person.
            p = AgentTester.Test <PersonAgent, Person>()
                .ExpectStatusCode(HttpStatusCode.Created)
                .ExpectChangeLogCreated()
                .ExpectETag()
                .ExpectUniqueKey()
                .ExpectValue((t) => p)
                .Run(a => a.CreateWithEfAsync(p)).Value;

            // Check the person was created properly.
            AgentTester.Test <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .ExpectValue((t) => p)
            .Run(a => a.GetWithEfAsync(p.Id));
        }
Exemple #12
0
        public void C130_Update()
        {
            // Get an existing value.
            var id = 2.ToGuid();
            var v  = AgentTester.Test <PersonAgent, Person?>()
                     .ExpectStatusCode(HttpStatusCode.OK)
                     .Run(a => a.GetAsync(id)).Value !;

            // Make some changes to the data.
            v.FirstName += "X";
            v.LastName  += "Y";

            // Update the value.
            v = AgentTester.Test <PersonAgent, Person>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .ExpectChangeLogUpdated()
                .ExpectETag(v.ETag)
                .ExpectUniqueKey()
                .ExpectValue(_ => v)
                .ExpectEvent($"Company.AppName.Person.{id}", "Updated")
                .Run(a => a.UpdateAsync(v, id)).Value !;

            // Check the value was updated properly.
            AgentTester.Test <PersonAgent, Person?>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .ExpectValue(_ => v)
            .Run(a => a.GetAsync(id));
        }
Exemple #13
0
 public void B310_GetWithEf_NotFound()
 {
     AgentTester.Test <PersonAgent, Person>()
     .ExpectStatusCode(HttpStatusCode.NotFound)
     .ExpectErrorType(Beef.ErrorType.NotFoundError)
     .Run(a => a.GetWithEfAsync(404.ToGuid()));
 }
Exemple #14
0
 public void B110_Get_NotFound()
 {
     AgentTester.Test <RobotAgent, Robot>()
     .ExpectStatusCode(HttpStatusCode.NotFound)
     .ExpectErrorType(Beef.ErrorType.NotFoundError)
     .Run(a => a.GetAsync(404.ToGuid()));
 }
Exemple #15
0
        public void F140_Update()
        {
            // Get an existing Robot.
            var v = AgentTester.Test <RobotAgent, Robot>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .ExpectNoEvents()
                    .Run(a => a.GetAsync(1.ToGuid())).Value;

            // Update the Robot with an address.
            v.ModelNo  += "X";
            v.SerialNo += "Y";

            v = AgentTester.Test <RobotAgent, Robot>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .ExpectChangeLogUpdated(ExecutionContext.Current.Username)
                .ExpectETag(v.ETag)
                .ExpectUniqueKey()
                .ExpectEventWithValue("Demo.Robot.*", "Update")
                .ExpectValue((t) => v)
                .Run(a => a.UpdateAsync(v, 1.ToGuid())).Value;

            // Check the Robot was updated properly.
            AgentTester.Test <RobotAgent, Robot>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .ExpectNoEvents()
            .ExpectValue((t) => v)
            .Run(a => a.GetAsync(v.Id));
        }
Exemple #16
0
        public void E110_Create()
        {
            AgentTester.PrepareExecutionContext();

            var r = new Robot
            {
                ModelNo     = "T500",
                SerialNo    = "321987",
                EyeColor    = "BLUE",
                PowerSource = "N"
            };

            // Create a robot.
            r = AgentTester.Test <RobotAgent, Robot>()
                .ExpectStatusCode(HttpStatusCode.Created)
                .ExpectChangeLogCreated()
                .ExpectETag()
                .ExpectUniqueKey()
                .ExpectEventWithValue("Demo.Robot.*", "Create")
                .ExpectValue((t) => r)
                .Run(a => a.CreateAsync(r)).Value;

            // Check the robot was created properly.
            AgentTester.Test <RobotAgent, Robot>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .ExpectValue((t) => r)
            .Run(a => a.GetAsync(r.Id));
        }
Exemple #17
0
 public void B110_GetPostCodes_NotFound()
 {
     AgentTester.Test <PostalInfoAgent, PostalInfo>()
     .ExpectStatusCode(HttpStatusCode.NotFound)
     .ExpectErrorType(Beef.ErrorType.NotFoundError)
     .Run(a => a.GetPostCodesAsync("NZ", "Y", "Z"));
 }
Exemple #18
0
 public void D130_GetBalance_NotFound_Auth()
 {
     // Try with a known id that is valid for another user.
     AgentTester.Test <AccountAgent, Balance?>()
     .ExpectStatusCode(HttpStatusCode.NotFound)
     .Run(a => a.GetBalanceAsync("12345678"));
 }
Exemple #19
0
 public void H110_Patch_NotFound()
 {
     // Patch with an invalid identifier.
     AgentTester.Test <PersonAgent, Person>()
     .ExpectStatusCode(HttpStatusCode.NotFound)
     .ExpectErrorType(ErrorType.NotFoundError)
     .Run(a => a.PatchAsync(WebApiPatchOption.MergePatch, JToken.Parse("{ \"firstName\": \"Barry\" }"), 404.ToGuid()));
 }
Exemple #20
0
 public void B140_Get_NotModified_Modified()
 {
     AgentTester.Test <RobotAgent, Robot>()
     .ExpectStatusCode(HttpStatusCode.OK)
     .Run(a => a.GetAsync(3.ToGuid(), new WebApi.WebApiRequestOptions {
         ETag = "ABCDEFG"
     }));
 }
Exemple #21
0
 public void B170_GetTransactions_Auth()
 {
     AgentTester.Test <TransactionAgent, TransactionCollectionResult>()
     .ExpectStatusCode(HttpStatusCode.Forbidden)
     .Run(a => a.GetTransactionsAsync("12345678", new TransactionArgs {
         FromDate = new DateTime(2019, 04, 01)
     }));
 }
Exemple #22
0
        public void D110_GetBalance_Found()
        {
            var v = AgentTester.Test <AccountAgent, Balance?>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetBalanceAsync("12345678")).Value;

            Assert.IsNotNull(v);
        }
Exemple #23
0
 public void B140_Get_NotModified_Modified()
 {
     AgentTester.Test <PersonAgent, Person>()
     .ExpectStatusCode(HttpStatusCode.OK)
     .RunOverride(() => new PersonAgent(new WebApiAgentArgs(AgentTester.GetHttpClient(), r =>
     {
         r.Headers.IfNoneMatch.Add(new System.Net.Http.Headers.EntityTagHeaderValue("\"ABCDEFG\""));
     })).GetAsync(3.ToGuid()));
 }
Exemple #24
0
 public void I150_GetNoArgs()
 {
     AgentTester.Test <PersonAgent, Person>()
     .ExpectStatusCode(HttpStatusCode.OK)
     .ExpectValue(_ => new Person {
         FirstName = "No", LastName = "Args"
     })
     .Run(a => a.GetNoArgsAsync());
 }
Exemple #25
0
        public void A140_GetGender()
        {
            var rd = AgentTester.Test <ReferenceDataAgent, GenderCollection>()
                     .ExpectStatusCode(HttpStatusCode.OK)
                     .Run(a => a.GenderGetAllAsync()).Value;

            Assert.IsNotNull(rd);
            Assert.Greater(rd.AllList.Count, 0);
        }
Exemple #26
0
 public void B120_Get()
 {
     AgentTester.Test <ProductAgent, Product>()
     .ExpectStatusCode(HttpStatusCode.OK)
     .ExpectValue((t) => new Product {
         Id = 1, Name = "Milk", Description = "Low fat milk"
     })
     .Run(a => a.GetAsync(1));
 }
Exemple #27
0
        public void C110_GetByArgs_Null()
        {
            var pcr = AgentTester.Test <ProductAgent, ProductCollectionResult>()
                      .ExpectStatusCode(HttpStatusCode.OK)
                      .Run(a => a.GetByArgsAsync(null));

            // Check 11 are returned.
            Assert.AreEqual(11, pcr?.Value?.Result?.Count);
        }
Exemple #28
0
 public void B120_Get_Found()
 {
     var p = AgentTester.Test <TripPersonAgent, TripPerson>()
             .ExpectStatusCode(HttpStatusCode.OK)
             .ExpectValue(_ => new TripPerson {
         Id = "willieashmore", FirstName = "Willie", LastName = "Ashmore"
     })
             .Run(a => a.GetAsync("willieashmore")).Value;
 }
Exemple #29
0
        public void A110_GetNamed_AllList()
        {
            var r = AgentTester.Test <ReferenceDataAgent>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetNamedAsync(new string[] { nameof(ReferenceData.Country), nameof(ReferenceData.USState), nameof(ReferenceData.Gender), nameof(ReferenceData.EyeColor), nameof(ReferenceData.PowerSource), nameof(ReferenceData.Company) }));

            Assert.NotNull(r.Content);
            Assert.AreEqual(6, JObject.Parse("{ \"content\":" + r.Content + "}")["content"].Children().Count());
        }
        public void A210_GetByEmployeeId_NotFound()
        {
            var v = AgentTester.Test <PerformanceReviewAgent, PerformanceReviewCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetByEmployeeIdAsync(4.ToGuid())).Value !;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(0, v.Result.Count);
        }