public void PostRetailLocation_ValidConceptId_Works()
        {
            var location = new RetailLocation
            {
                Id                 = $"{TestLocationIdPrefix}WithValidConceptIdTest",
                LocationName       = "No physical address test",
                PrimaryPhoneNumber = "858-555-1212",
                FaxNumber          = "555-1212",
                ExtraInformation   = new Dictionary <string, string>
                {
                    { "Lots", "OfStuff" }
                },
                PhysicalAddress = new Address
                {
                    Address1          = "PO Box 12345",
                    City              = "San Diego",
                    StateProvinceCode = "CA",
                    CountryCode       = "US"
                },
                Concepts = new List <string> {
                    UnitTestConceptId
                }
            };

            var result = _api.PostRetailLocation(location);

            Assert.That(result.Concepts, Is.Not.Null.And.Empty);
            Assert.That(result.Concepts[0], Is.EqualTo(location.Concepts[0]));
        }
        public void PostRetailLocation_NoPhysicalAddress_ThrowsException()
        {
            var location = new RetailLocation
            {
                Id                 = "NoPhysicalAddressTest",
                LocationName       = "No physical address test",
                PrimaryPhoneNumber = "858-555-1212",
                FaxNumber          = "555-1212",
                ExtraInformation   = new Dictionary <string, string>
                {
                    { "Lots", "OfStuff" }
                },
                MailingAddress = new Address
                {
                    Address1          = "PO Box 12345",
                    City              = "San Diego",
                    StateProvinceCode = "CA",
                    CountryCode       = "US"
                },
                PhysicalAddress = null //<-- this is required actually.
            };


            var ex = Assert.Throws <HttpRequestException>(() =>
            {
                _api.PostRetailLocation(location);
            });

            Assert.That(ex.Message, Is.StringContaining("not provided"));
        }
        public void PostRetailLocation_InvalidCountryCode_ThrowsException(string physicalAddressCountryCode, string mailingAddressCountryCode)
        {
            var location = new RetailLocation
            {
                Id                 = "InvalidCountryCodeTest",
                LocationName       = "Invalid Country Code Test",
                PrimaryPhoneNumber = "858-555-1212",
                FaxNumber          = "555-1212",
                PhysicalAddress    = new Address
                {
                    Address1          = "123 Main St",
                    City              = "San Diego",
                    StateProvinceCode = "CA",
                    ZipCode           = "92109",
                    CountryCode       = physicalAddressCountryCode
                },
                MailingAddress = new Address
                {
                    Address1          = "PO BOX 123456",
                    City              = "San Diego",
                    StateProvinceCode = "CA",
                    ZipCode           = "92109",
                    CountryCode       = mailingAddressCountryCode
                }
            };

            var ex = Assert.Throws <HttpRequestException>(() =>
            {
                //insert records w/ POST, will throw if already exists.
                //Use PUT to update.
                _api.PostRetailLocation(location);
            });

            Assert.That(ex.Message, Is.StringContaining("not a valid country code"));
        }
        public void PostRetailLocation_WithMissingRequiredFields_ThrowsException(string id, string name, string address1,
                                                                                 string city, string countryCode)
        {
            var location = new RetailLocation
            {
                Id                 = id,
                LocationName       = name,
                FaxNumber          = null,
                PrimaryPhoneNumber = null,
                ExtraInformation   = null,
                MailingAddress     = null,
                PhysicalAddress    = new Address
                {
                    Address1    = address1,
                    City        = city,
                    CountryCode = countryCode
                }
            };


            var ex = Assert.Throws <HttpRequestException>(() =>
            {
                _api.PostRetailLocation(location);
            });

            Assert.That(ex.Message, Is.StringContaining("not provided"));
        }
Пример #5
0
        static void Main(string[] args)
        {
            //Create the old entry
            RetailLocation oldLocation = new RetailLocation()
            {
                Id               = 1,
                DateOpened       = new DateTime(2009, 12, 3),
                ManagerFirstName = "Steve",
                ManagerLastName  = "Harkonnen",
                HasLimitedMenu   = true
            };

            RetailLocation newLocation = new RetailLocation()
            {
                Id               = 1,
                DateOpened       = new DateTime(2009, 12, 3),
                ManagerFirstName = "Kelly",
                ManagerLastName  = "Nishimura",
                HasLimitedMenu   = false
            };

            ChangeLogService service = new ChangeLogService();
            var logs = service.GetChanges(oldLocation, newLocation);

            foreach (var log in logs)
            {
                Console.WriteLine("Primary Key: " + log.PrimaryKey.ToString() + ", Class Name:" + log.ClassName + ", Property Name: " + log.PropertyName + ", Old Value = " + log.OldValue + ", New Value = " + log.NewValue);
            }
        }
        public void PutRetailLocation_AllMembersNull_ThrowsException()
        {
            var location = new RetailLocation();

            var ex = Assert.Throws <HttpRequestException>(() =>
            {
                _api.PutRetailLocation(location);
            });

            Assert.That(ex.Message, Is.StringContaining("Not Allowed").IgnoreCase);
        }
        public void DeleteRetailLocation_ActiveLocation_CannotGetAndCannotList()
        {
            var deleteMeLocationId = $"{TestLocationIdPrefix}For_Deletion_3"; //increment the # after succesful test runs or delete all data w/ a batch file and RQLCMD commands.(see QueryStores,DelStores).

            var retailLocation = new RetailLocation
            {
                Id                 = deleteMeLocationId,
                LocationName       = "Location For Deletion Unit Test",
                PrimaryPhoneNumber = "858-555-1212",
                FaxNumber          = "555-1212",
                PhysicalAddress    = new Address
                {
                    Address1          = "123 Happy St",
                    City              = "San Diego",
                    StateProvinceCode = "CA",
                    CountryCode       = "US"
                }
            };

            var locationToDelete = _api.PostRetailLocation(retailLocation);

            var locationAfterPost = _api.GetRetailLocation(deleteMeLocationId);

            Assert.IsNotNull(locationAfterPost, "Should be able to GET it after POSTing it...");

            var allLocationsAfterPost = _api.ListRetailLocations();

            Assert.That(allLocationsAfterPost.Select(a => a.Id).ToList(), Has.Some.Contains(locationToDelete.Id));

            _api.DeleteRetailLocation(deleteMeLocationId);

            //should get error 404 - not found
            var ex = Assert.Throws <HttpRequestException>(() => _api.GetRetailLocation(deleteMeLocationId));

            Assert.That(ex.Message, Is.StringContaining("404"));

            //should not be listed either
            var allLocationsAfterDelete = _api.ListRetailLocations();

            Assert.That(allLocationsAfterDelete.Select(a => a.Id).ToList(), Has.None.Contains(deleteMeLocationId));
        }
        public void FixtureSetup()
        {
            _allContactTypeIds = _api.ListContactTypes()
                                 .Select(ct => ct.ContactTypeCode)
                                 .ToList();

            Assert.That(_allContactTypeIds, Is.Not.Null.And.Not.Empty,
                        "Why didn't API return Contact Types?  See Admin->Core App Master Queues->Custom Dropdowns->Custom Dropdown Items, with Dropdown_Group_ID filter set to 'Contact Type'");

            _allProfileIds = _api.ListProfiles().Select(p => p.ProfileId).ToList();

            Assert.That(_allProfileIds, Is.Not.Null.And.Count.GreaterThan(1),
                        "Why didn't API return Profiles? Ensure that Profile Records exist and that some are Active.  See the queue at Admin->Permissions Management->Profiles for the current site.");

            _allEntityTypeIds = _api.ListEntityTypes().Select(et => et.EntityTypeId)
                                .ToList();

            Assert.That(_allEntityTypeIds, Is.Not.Null.And.Count.GreaterThan(1),
                        "Why didn't API return Entity Types? See Admin->Core App Master Queues->Business Types");

            _sampleLocation = CreateSampleLocation();
        }
        public void PostRetailLocation_InvalidConceptId_ThrowsException()
        {
            var location = new RetailLocation
            {
                Id                 = $"{TestLocationIdPrefix}WithInvalidConceptIdTest",
                LocationName       = "No physical address test",
                PrimaryPhoneNumber = "858-555-1212",
                FaxNumber          = "555-1212",
                ExtraInformation   = new Dictionary <string, string>
                {
                    { "Lots", "OfStuff" }
                },
                PhysicalAddress = new Address
                {
                    Address1          = "PO Box 12345",
                    City              = "San Diego",
                    StateProvinceCode = "CA",
                    CountryCode       = "US"
                },
                MailingAddress = new Address
                {
                    Address1          = "PO Box 12345",
                    City              = "San Diego",
                    StateProvinceCode = "CA",
                    CountryCode       = "US"
                },
                Concepts = new List <string> {
                    "no such concept id"
                }
            };

            var ex = Assert.Throws <HttpRequestException>(() =>
            {
                _api.PostRetailLocation(location);
            });

            Assert.That(ex.Message, Is.StringContaining("Invalid Concept").IgnoreCase);
        }
        public void RetailLocation_ToJson_ThenToXml()
        {
            var location = new RetailLocation
            {
                Id                 = "Location 123",
                LocationName       = "Location 123 Name",
                FaxNumber          = "555-1212",
                PrimaryPhoneNumber = "555-1212",
                PhysicalAddress    = new Address
                {
                    Address1          = "123 Happy St",
                    Address2          = null,
                    City              = "San Diego",
                    StateProvinceCode = "CA",
                    ZipCode           = "92109",
                    CountryCode       = "US"
                },
                MailingAddress = new Address
                {
                    Address1          = "Major Company Receiving Department",
                    Address2          = "PO BOX 1234567",
                    City              = "San Diego",
                    StateProvinceCode = "CA",
                    ZipCode           = "92109",
                    CountryCode       = "US"
                },
                Concepts = new List <string> {
                    "123"
                },
                ExtraInformation = new Dictionary <string, string> {
                    { "Department", "Meat" }
                }
            };

            SerializeToJsonThenToXml(location);
        }
        public void PutRetailLocation_NoSuchId_ThrowsException()
        {
            var location = new RetailLocation
            {
                Id              = "No such Id 123k1-094-0`i8 ]9t0pj3pvkmas ;",
                LocationName    = "Name Of Location that has Id that doesn't exist",
                PhysicalAddress = new Address
                {
                    Address1          = "123 Main St",
                    City              = "San Diego",
                    StateProvinceCode = "CA",
                    CountryCode       = "US"
                }
            };

            var ex = Assert.Throws <HttpRequestException>(() =>
            {
                _api.PutRetailLocation(location);
            });

            Assert.That(ex.Message, Is
                        .StringContaining("not found").IgnoreCase.Or
                        .StringContaining("not exist").IgnoreCase);//IIS vs. self hosting result
        }
        private void CreateTestRetailLocations()
        {
            var allRetailLocationIds = _api.ListAllRetailLocations()
                                       .Select(a => a.Id)
                                       .ToList();

            var retailLocations = Enumerable.Range(1, NumberOfTestRetailLocations).Select(i =>
            {
                var retailLocationId = $"{TestLocationIdPrefix}{i}";

                var extraInfoKey2   = $"StuffWithDifferentKey_{i}";
                var extraInfoValue2 = $"Value {i}";
                var location        = new RetailLocation
                {
                    Id                 = retailLocationId,
                    LocationName       = $"Test Location {i}",
                    PrimaryPhoneNumber = "858-555-1212",
                    FaxNumber          = "555-1212",
                    PhysicalAddress    = new Address
                    {
                        Address1          = "123 Main St",
                        City              = "San Diego",
                        StateProvinceCode = "CA",
                        ZipCode           = "92109",
                        CountryCode       = "US"
                    },
                    MailingAddress = new Address
                    {
                        Address1          = "PO BOX 123456",
                        City              = "San Diego",
                        StateProvinceCode = "CA",
                        ZipCode           = "92109",
                        CountryCode       = "US",
                    },
                    ExtraInformation = new Dictionary <string, string>
                    {
                        { "Division", "Division 1" },
                        { "ExtraStuff", $"Extra Stuff Value {i}" },
                        { extraInfoKey2, extraInfoValue2 }
                    }
                };
                if (!allRetailLocationIds.Contains(retailLocationId))
                {
                    var result = _api.PostRetailLocation(location);
                    //  var result = _api.PutRetailLocation(location);

                    Assert.That(result.Id, Is.EqualTo(location.Id));
                    Assert.That(result.LocationName, Is.EqualTo(location.LocationName));
                    Assert.That(result.PrimaryPhoneNumber, Is.EqualTo(location.PrimaryPhoneNumber));
                    Assert.That(result.FaxNumber, Is.EqualTo(location.FaxNumber));
                    Assert.That(result.PhysicalAddress, Is.Not.Null);
                    Assert.That(result.PhysicalAddress.Address1, Is.EqualTo(location.PhysicalAddress.Address1));
                    Assert.That(result.PhysicalAddress.Address2, Is.Null.Or.Empty);
                    Assert.That(result.PhysicalAddress.City, Is.EqualTo(location.PhysicalAddress.City));
                    Assert.That(result.PhysicalAddress.ZipCode, Is.EqualTo(location.PhysicalAddress.ZipCode));
                    Assert.That(result.PhysicalAddress.CountryCode, Is.EqualTo(location.PhysicalAddress.CountryCode));
                    Assert.That(result.MailingAddress, Is.Not.Null);
                    Assert.That(result.MailingAddress.Address1, Is.EqualTo(location.MailingAddress.Address1));
                    Assert.That(result.MailingAddress.Address2, Is.Null.Or.Empty);
                    Assert.That(result.MailingAddress.Address3, Is.Null.Or.Empty);
                    Assert.That(result.MailingAddress.City, Is.EqualTo(location.MailingAddress.City));
                    Assert.That(result.MailingAddress.StateProvinceCode, Is.EqualTo(location.MailingAddress.StateProvinceCode));
                    Assert.That(result.MailingAddress.ZipCode, Is.EqualTo(location.MailingAddress.ZipCode));
                    Assert.That(result.MailingAddress.CountryCode, Is.EqualTo(location.MailingAddress.CountryCode));


                    Assert.That(result.ExtraInformation, Is.Not.Null.And.Not.Empty);
                    Assert.That(result.ExtraInformation[extraInfoKey2], Is.EqualTo(extraInfoValue2));
                }

                return(location);
            }).ToList();


            Assert.That(retailLocations.Count, Is.EqualTo(NumberOfTestRetailLocations));
        }
Пример #13
0
 public static RetailLocation PostRetailLocation(this RestfulBusinessApiClient api,
                                                 RetailLocation retailRetailLocation)
 {
     return(api.PostJson <RetailLocation>("RetailLocations", retailRetailLocation));
 }
Пример #14
0
 public static RetailLocation PutRetailLocation(this RestfulBusinessApiClient api,
                                                RetailLocation retailRetailLocation)
 {
     return(api.PutJson <RetailLocation>("RetailLocations/" + retailRetailLocation.Id.UrlEncode(),
                                         retailRetailLocation));
 }