예제 #1
0
 public void A160_Validation_Detail_History_Duplicate()
 {
     AgentTester.Create <PersonAgent, PersonDetail>()
     .ExpectStatusCode(HttpStatusCode.BadRequest)
     .ExpectErrorType(ErrorType.ValidationError)
     .ExpectMessages("History contains duplicates; Name value 'Google' specified more than once.")
     .Run((a) => a.Agent.UpdateDetailAsync(new PersonDetail()
     {
         FirstName = "Barry", LastName = "Smith", Birthday = DateTime.Now.AddDays(-5000), Gender = "M", EyeColor = "BROWN",
         History   = new WorkHistoryCollection {
             new WorkHistory {
                 Name = "Google", StartDate = new DateTime(1990, 12, 31)
             },
             new WorkHistory {
                 Name = "Google", StartDate = new DateTime(1992, 12, 31)
             }
         }
     }, 1.ToGuid()));
 }
예제 #2
0
        public void Validate()
        {
            // Run a randon agent to make sure the API is up and running.
            AgentTester.Create <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.NotFound)
            .Run((a) => a.Agent.GetAsync(404.ToGuid()));

            Assert.AreEqual(25, PagingArgs.DefaultTake);

            var p = CachePolicyManager.DefaultPolicy;

            Assert.NotNull(p);
            Assert.IsInstanceOf(typeof(SlidingCachePolicy), p);

            var scp = (SlidingCachePolicy)p;

            Assert.AreEqual(new TimeSpan(00, 30, 00), scp.Duration);
            Assert.AreEqual(new TimeSpan(02, 00, 00), scp.MaxDuration);
        }
예제 #3
0
        public void B270_GetByArgs_RefDataText()
        {
            var r = AgentTester.Create <PersonAgent, PersonCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetByArgsAsync(new PersonArgs {
                GendersSids = new List <string> {
                    "F"
                }
            }, requestOptions: new WebApiRequestOptions {
                IncludeRefDataText = true
            }));

            Assert.IsNotNull(r.Value);
            Assert.IsNotNull(r.Value.Result);
            Assert.AreEqual(2, r.Value.Result.Count);
            Assert.AreEqual(new string[] { "Browne", "Jones" }, r.Value.Result.Select(x => x.LastName).ToArray());

            Assert.AreEqual(2, Newtonsoft.Json.Linq.JArray.Parse(r.Content !).Descendants().OfType <Newtonsoft.Json.Linq.JProperty>().Where(p => p.Name == "genderText").Count());
        }
예제 #4
0
        public void A120_PowerSourceChangeSubscriber_Updated()
        {
            var r = AgentTester.Create <RobotAgent, Robot>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.Agent.GetAsync(1.ToGuid())).Value;

            r.PowerSourceSid = "N";

            EventSubscriberTester.Create <PowerSourceChangeSubscriber>()
            .ExpectResult(SubscriberStatus.Success)
            .ExpectEvent($"Demo.Robot.{r.Id}", "Update")
            .Run(EventData.CreateValueEvent(r.PowerSourceSid, $"Demo.Robot.{r.Id}", "PowerSourceChange", r.Id));

            AgentTester.Create <RobotAgent, Robot>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .ExpectChangeLogUpdated("*")
            .ExpectETag(r.ETag)
            .ExpectValue(_ => r)
            .Run(a => a.Agent.GetAsync(1.ToGuid()));
        }
예제 #5
0
        public void G120_Delete()
        {
            // Check Robot exists.
            AgentTester.Create <RobotAgent, Robot>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .ExpectNoEvents()
            .Run((a) => a.Agent.GetAsync(1.ToGuid()));

            // Delete a Robot.
            AgentTester.Create <RobotAgent>()
            .ExpectStatusCode(HttpStatusCode.NoContent)
            .ExpectEvent("Demo.Robot.*", "Delete")
            .Run((a) => a.Agent.DeleteAsync(1.ToGuid()));

            // Check Robot no longer exists.
            AgentTester.Create <RobotAgent, Robot>()
            .ExpectStatusCode(HttpStatusCode.NotFound)
            .ExpectErrorType(Beef.ErrorType.NotFoundError)
            .ExpectNoEvents()
            .Run((a) => a.Agent.GetAsync(1.ToGuid()));
        }
예제 #6
0
        public void H130_Patch_MergePatch()
        {
            // Get an existing person.
            var p = AgentTester.Create <PersonAgent, Person>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetAsync(3.ToGuid())).Value;

            p.FirstName = "Barry";
            p.Address   = new Address {
                Street = "Simpsons Road", City = "Bardon"
            };

            // Try patching the person with an invalid eTag.
            p = AgentTester.Create <PersonAgent, Person>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .ExpectETag(p.ETag)
                .ExpectChangeLogUpdated()
                .ExpectValue(_ => p)
                .Run((a) => a.Agent.PatchAsync(WebApiPatchOption.MergePatch,
                                               JToken.Parse("{ \"firstName\": \"Barry\", \"address\": { \"street\": \"Simpsons Road\", \"city\": \"Bardon\" } }"),
                                               3.ToGuid(), new WebApiRequestOptions {
                ETag = p.ETag
            })).Value;

            // Check the person was patched properly.
            p = AgentTester.Create <PersonAgent, Person>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .ExpectValue(_ => p)
                .Run((a) => a.Agent.GetAsync(3.ToGuid())).Value;

            // Try a re-patch with no changes.
            p = AgentTester.Create <PersonAgent, Person>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .ExpectValue(_ => p)
                .Run((a) => a.Agent.PatchAsync(WebApiPatchOption.MergePatch,
                                               JToken.Parse("{ \"firstName\": \"Barry\", \"address\": { \"street\": \"Simpsons Road\", \"city\": \"Bardon\" } }"),
                                               3.ToGuid(), new WebApiRequestOptions {
                ETag = p.ETag
            })).Value;
        }
예제 #7
0
        public void H160_PatchDetail_MergePatch_Error()
        {
            // Get an existing person detail.
            var p = AgentTester.Create <PersonAgent, PersonDetail>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetDetailAsync(4.ToGuid())).Value;

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

            AgentTester.Create <PersonAgent, PersonDetail>()
            .ExpectStatusCode(HttpStatusCode.BadRequest)
            .ExpectErrorType(ErrorType.ValidationError)
            .ExpectMessages(
                "The JSON object must specify the 'name' token as required for the unique key.",
                "The JSON token is malformed: The string 'xxx' was not recognized as a valid DateTime. There is an unknown word starting at index '0'.")
            .Run((a) => a.Agent.PatchDetailAsync(WebApiPatchOption.MergePatch, jt, 4.ToGuid(), new WebApiRequestOptions {
                ETag = p.ETag
            }));
        }
예제 #8
0
 public void C120_GetDetail_Found()
 {
     AgentTester.Create <AccountAgent, AccountDetail>()
     .ExpectStatusCode(HttpStatusCode.OK)
     .ExpectValue(_ => new AccountDetail
     {
         Id            = "12345678",
         Bsb           = "020780",
         AccountNumber = "12345678",
         CreditCard    = new CreditCardAccount {
             MinPaymentAmount = 100m, PaymentDueAmount = 326.59m, PaymentDueDate = new DateTime(2020, 06, 01)
         },
         CreationDate    = new DateTime(1985, 03, 18),
         DisplayName     = "Savings",
         Nickname        = "Save",
         OpenStatus      = "OPEN",
         IsOwned         = true,
         MaskedNumber    = "XXXXXX78",
         ProductCategory = "TRANS_AND_SAVINGS_ACCOUNTS"
     })
     .Run((a) => a.Agent.GetDetailAsync("12345678"));
 }
예제 #9
0
        public void D120_Update_Concurrency()
        {
            // Get an existing value.
            var v = AgentTester.Create <PersonAgent, Person>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetAsync(2.ToGuid())).Value;

            // Try updating the value with an invalid eTag (if-match).
            AgentTester.Create <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.PreconditionFailed)
            .ExpectErrorType(ErrorType.ConcurrencyError)
            .Run((a) => a.Agent.UpdateAsync(v, 2.ToGuid(), new WebApiRequestOptions {
                ETag = AgentTester.ConcurrencyErrorETag
            }));

            // Try updating the value with an invalid eTag.
            v.ETag = AgentTester.ConcurrencyErrorETag;
            AgentTester.Create <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.PreconditionFailed)
            .ExpectErrorType(ErrorType.ConcurrencyError)
            .Run((a) => a.Agent.UpdateAsync(v, 2.ToGuid()));
        }
예제 #10
0
        public void A110_Get()
        {
            var r = AgentTester.Create <ContactAgent, Contact>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .ExpectValue((t) => new Contact {
                Id = 1.ToGuid(), FirstName = "Jenny", LastName = "Cuthbert"
            })
                    .Run((a) => a.Agent.GetAsync(1.ToGuid()));

            Assert.NotNull(r.Response.Headers?.ETag?.Tag);
            var etag = r.Response.Headers?.ETag?.Tag;

            r = AgentTester.Create <ContactAgent, Contact>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .ExpectValue((t) => new Contact {
                Id = 1.ToGuid(), FirstName = "Jenny", LastName = "Cuthbert"
            })
                .Run((a) => a.Agent.GetAsync(1.ToGuid()));

            Assert.NotNull(r.Response.Headers?.ETag?.Tag);
            Assert.AreEqual(etag, r.Response.Headers?.ETag?.Tag);
        }
예제 #11
0
        public void F120_Update_Concurrency()
        {
            // Get an existing person.
            var p = AgentTester.Create <PersonAgent, Person>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetAsync(1.ToGuid())).Value;

            // Try with an invalid If-Match value.
            AgentTester.Create <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.PreconditionFailed)
            .ExpectErrorType(ErrorType.ConcurrencyError)
            .Run((a) => a.Agent.UpdateAsync(p, 1.ToGuid(), new WebApiRequestOptions {
                ETag = AgentTester.ConcurrencyErrorETag
            }));

            // Try updating the person with an invalid eTag.
            p.ETag = AgentTester.ConcurrencyErrorETag;

            AgentTester.Create <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.PreconditionFailed)
            .ExpectErrorType(ErrorType.ConcurrencyError)
            .Run((a) => a.Agent.UpdateAsync(p, 1.ToGuid()));
        }
예제 #12
0
파일: PersonTest.cs 프로젝트: nissan/Beef
        public void E120_Patch_Concurrency()
        {
            // Get an existing value.
            var id = 2.ToGuid();
            var v  = AgentTester.Create <PersonAgent, Person>()
                     .ExpectStatusCode(HttpStatusCode.OK)
                     .Run((a) => a.Agent.GetAsync(id)).Value;

            // Try updating the value with an invalid eTag (if-match).
            AgentTester.Create <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.PreconditionFailed)
            .ExpectErrorType(ErrorType.ConcurrencyError)
            .Run((a) => a.Agent.PatchAsync(WebApiPatchOption.MergePatch, "{ \"lastName\": \"Smithers\" }", id, new WebApiRequestOptions {
                ETag = AgentTester.ConcurrencyErrorETag
            }));

            // Try updating the value with an eTag header (json payload eTag is ignored).
            v.ETag = AgentTester.ConcurrencyErrorETag;
            AgentTester.Create <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.PreconditionFailed)
            .ExpectErrorType(ErrorType.ConcurrencyError)
            .Run((a) => a.Agent.PatchAsync(WebApiPatchOption.MergePatch, "{{ \"lastName\": \"Smithers\", \"etag\": {AgentTester.ConcurrencyErrorETag} }}", id));
        }
예제 #13
0
        public void E110_Delete()
        {
            // Check value exists.
            AgentTester.Create <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .Run((a) => a.Agent.GetAsync(4.ToGuid()));

            // Delete value.
            AgentTester.Create <PersonAgent>()
            .ExpectStatusCode(HttpStatusCode.NoContent)
            .Run((a) => a.Agent.DeleteAsync(4.ToGuid()));

            // Check value no longer exists.
            AgentTester.Create <PersonAgent, Person>()
            .ExpectStatusCode(HttpStatusCode.NotFound)
            .ExpectErrorType(Beef.ErrorType.NotFoundError)
            .Run((a) => a.Agent.GetAsync(4.ToGuid()));

            // Delete again (should still be successful).
            AgentTester.Create <PersonAgent>()
            .ExpectStatusCode(HttpStatusCode.NoContent)
            .Run((a) => a.Agent.DeleteAsync(4.ToGuid()));
        }
예제 #14
0
        public void A150_GetGender_NotModified()
        {
            var r = AgentTester.Create <ReferenceDataAgent, GenderCollection>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GenderGetAllAsync());

            r.Response.Headers.TryGetValues("ETag", out var vals);
            Assert.IsNotNull(vals);
            Assert.AreEqual(1, vals.Count());

            AgentTester.Create <ReferenceDataAgent, GenderCollection>()
            .ExpectStatusCode(HttpStatusCode.NotModified)
            .Run((a) => new ReferenceDataAgent(a.Client, (x) =>
            {
                x.Headers.IfNoneMatch.Add(new System.Net.Http.Headers.EntityTagHeaderValue(vals.First()));
            }).GenderGetAllAsync());

            AgentTester.Create <ReferenceDataAgent, GenderCollection>()
            .ExpectStatusCode(HttpStatusCode.NotModified)
            .Run((a) => a.Agent.GenderGetAllAsync(null, new WebApi.WebApiRequestOptions {
                ETag = vals.First()
            }));
        }
예제 #15
0
        public void F150_UpdateDetail()
        {
            // Get an existing person detail.
            var p = AgentTester.Create <PersonAgent, PersonDetail>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetDetailAsync(2.ToGuid())).Value;

            // Update the work history.
            p.History[0].StartDate = p.History[0].StartDate.AddDays(1);

            p = AgentTester.Create <PersonAgent, PersonDetail>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .ExpectChangeLogUpdated()
                .ExpectETag(p.ETag)
                .ExpectUniqueKey()
                .ExpectValue((t) => p)
                .Run((a) => a.Agent.UpdateDetailAsync(p, 2.ToGuid())).Value;

            // Check the person detail was updated properly.
            p = AgentTester.Create <PersonAgent, PersonDetail>()
                .ExpectStatusCode(HttpStatusCode.OK)
                .ExpectValue((t) => p)
                .Run((a) => a.Agent.GetDetailAsync(p.Id)).Value;
        }
예제 #16
0
        public void E110_Create()
        {
            var r = new Robot
            {
                ModelNo  = "T500",
                SerialNo = "321987",
                EyeColor = "BLUE"
            };

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

            // Check the robot was created properly.
            AgentTester.Create <RobotAgent, Robot>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .ExpectValue((t) => r)
            .Run((a) => a.Agent.GetAsync(r.Id));
        }
예제 #17
0
 public void A150_Validation_Detail_History_Invalid()
 {
     AgentTester.Create <PersonAgent, PersonDetail>()
     .ExpectStatusCode(HttpStatusCode.BadRequest)
     .ExpectErrorType(ErrorType.ValidationError)
     .ExpectMessages(
         "End Date must be greater than or equal to Start Date.",
         "Start Date must be less than or equal to today.")
     .Run((a) => a.Agent.UpdateDetailAsync(new PersonDetail()
     {
         FirstName = "Barry",
         LastName  = "Smith",
         Birthday  = DateTime.Now.AddDays(-5000),
         Gender    = "M",
         History   = new WorkHistoryCollection {
             new WorkHistory {
                 Name = "Amazon", StartDate = new DateTime(1990, 12, 31), EndDate = new DateTime(1980, 10, 31)
             },
             new WorkHistory {
                 Name = "Google", StartDate = new DateTime(2999, 12, 31), EndDate = new DateTime(2000, 10, 31)
             }
         }
     }, 1.ToGuid()));
 }
예제 #18
0
 public void B140_GetAccounts_User4_Auth()
 {
     AgentTester.Create <AccountAgent, AccountCollectionResult>()
     .ExpectStatusCode(HttpStatusCode.Forbidden)
     .Run((a) => a.Agent.GetAccountsAsync(null));
 }
예제 #19
0
 public void A190_Get_NoContent()
 {
     var r = AgentTester.Create <ReferenceDataAgent>()
             .ExpectStatusCode(HttpStatusCode.OK)
             .Run((a) => a.Agent.GetNamedAsync(null));
 }
예제 #20
0
 public void C110_GetDetail_NotFound()
 {
     AgentTester.Create <AccountAgent, AccountDetail>()
     .ExpectStatusCode(HttpStatusCode.NotFound)
     .Run((a) => a.Agent.GetDetailAsync("00000000"));
 }
예제 #21
0
 public void C140_GetDetail_NoAuth()
 {
     AgentTester.Create <AccountAgent, AccountDetail>()
     .ExpectStatusCode(HttpStatusCode.Forbidden)
     .Run((a) => a.Agent.GetDetailAsync("12345678"));
 }
예제 #22
0
 public void D120_GetBalance_NotFound()
 {
     AgentTester.Create <AccountAgent, Balance>()
     .ExpectStatusCode(HttpStatusCode.NotFound)
     .Run((a) => a.Agent.GetBalanceAsync("00000000"));
 }
예제 #23
0
 public void D140_GetBalance_NoAuth()
 {
     AgentTester.Create <AccountAgent, Balance>()
     .ExpectStatusCode(HttpStatusCode.Forbidden)
     .Run((a) => a.Agent.GetBalanceAsync("00000000"));
 }
예제 #24
0
 public void B110_Get_NotFound()
 {
     AgentTester.Create <PersonAgent, Person>()
     .ExpectStatusCode(HttpStatusCode.NotFound)
     .Run((a) => a.Agent.GetAsync(404.ToGuid()));
 }
예제 #25
0
 public void I130_Null()
 {
     AgentTester.Create <PersonAgent, Person>()
     .ExpectStatusCode(HttpStatusCode.NotFound)
     .Run((a) => a.Agent.GetNullAsync("blah"));
 }