private async Task <Country> Given_ACountryInTheDatabaseWithSomeUpdatedProperties_When_UpdateCountryIsInvokedWithTheUpdatedCountry_Then_TheUpdatedCountryIsReturned(Country country)
        {
            try
            {
                country.Alpha2Code          = TestData.CaCountryAbbreviation;
                country.FullName            = TestData.CaCountryName;
                country.PhoneNumberRegex    = TestData.CaPhoneNumberRegex;
                country.PostalCodeRegex     = TestData.CaPostalCodeRegex;
                country.CreatedByUserId     = TestData.CountryCreatedByIdForUpdate;
                country.CreatedOn           = TestData.NonServiceGeneratedCountryCreatedOn;
                country.LastUpdatedByUserId = TestData.CountryLastUpdatedById;
                country.LastUpdatedOn       = TestData.NonServiceGeneratedCountryLastUpdatedOn;

                var countryReturned = await CountriesClient.UpdateCountry(country);

                Assert.AreEqual(TestData.CaCountryAbbreviation, countryReturned.Alpha2Code);
                Assert.AreEqual(TestData.CaCountryName, countryReturned.FullName);
                Assert.AreEqual(TestData.CaPhoneNumberRegex, countryReturned.PhoneNumberRegex);
                Assert.AreEqual(TestData.CaPostalCodeRegex, countryReturned.PostalCodeRegex);
                Assert.AreNotEqual(TestData.CountryCreatedByIdForUpdate, countryReturned.CreatedByUserId);
                Assert.AreNotEqual(TestData.NonServiceGeneratedCountryCreatedOn, countryReturned.CreatedOn);
                Assert.AreEqual(country.Id, countryReturned.Id);
                Assert.AreEqual(TestData.CountryLastUpdatedById, countryReturned.LastUpdatedByUserId);
                Assert.AreNotEqual(TestData.NonServiceGeneratedCountryLastUpdatedOn, countryReturned.LastUpdatedOn);

                country = countryReturned;
            }
            catch (Exception e)
            {
                Assert.Fail($"{e.Message}\n{e.StackTrace}");
            }

            return(country);
        }
Пример #2
0
        public MainProcessor(string connectionString, IDictionary <string, VaultDetails> vaultDetails,
                             string thumbnailsUrlPattern, string brsTermsUrlPattern, string leoTermsUrlPattern, CountriesClient countries,
                             ConferencesClient conferences, bool deleteNotInList)
        {
            ConnectionString     = connectionString;
            VaultDetails         = vaultDetails;
            Countries            = countries;
            Conferences          = conferences;
            ThumbnailsUrlPattern = thumbnailsUrlPattern;
            BrsTermsUrlPattern   = brsTermsUrlPattern;
            LeoTermsUrlPattern   = leoTermsUrlPattern;
            DeleteNotInList      = deleteNotInList;

            _ctx = new DocumentsContext(connectionString);
            _ctx.Database.CreateIfNotExists();
            var connectionForDisplay = _ctx.Database.Connection.ConnectionString.Split(';')[0];

            ClassLogger.Info($"Connection string {connectionForDisplay}");


            foreach (var type in ListPropertyTypesNames.Names)
            {
                if (_ctx.ValueTypes.FirstOrDefault(x => x.Name == type) == null)
                {
                    _ctx.ValueTypes.Add(new ListPropertyType {
                        ListPropertyTypeId = Guid.NewGuid(), Name = type
                    });
                }
            }
            _ctx.SaveChanges();
        }
Пример #3
0
        public static Tuple <string, bool> GetAuthor(ObjectVersionWrapper obj, CountriesClient countries)
        {
            var author  = obj.Author;
            var cauthor = obj.CorporateAuthor;
            var player  = obj.Player;

            if (!string.IsNullOrWhiteSpace(author))
            {
                return(new Tuple <string, bool>(author, false));
            }

            if (!string.IsNullOrEmpty(cauthor))
            {
                return(new Tuple <string, bool>(cauthor, true));
            }

            /*if (!string.IsNullOrEmpty(player))
             * {
             *  var country = countries.GetCountryIsoCode2(obj.Player);
             *  if (country != null)
             *  {
             *      return new Tuple<string, bool>(player, true);
             *  }
             * }*/

            return(null);
        }
Пример #4
0
        public CountryController(IMapper mapper, CountriesClient client)
        {
            mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
            client = client ?? throw new ArgumentException(nameof(client));

            this.mapper = mapper;
            this.client = client;
        }
Пример #5
0
        public ViagogoClient(
            ProductHeaderValue product,
            IGogoKitConfiguration configuration,
            IOAuth2TokenStore tokenStore,
            IJsonSerializer serializer,
            IHttpConnection oauthConnection,
            IHttpConnection apiConnection)
        {
            Requires.ArgumentNotNull(product, nameof(product));
            Requires.ArgumentNotNull(configuration, nameof(configuration));
            Requires.ArgumentNotNull(tokenStore, nameof(tokenStore));
            Requires.ArgumentNotNull(serializer, nameof(serializer));
            Requires.ArgumentNotNull(oauthConnection, nameof(oauthConnection));
            Requires.ArgumentNotNull(apiConnection, nameof(apiConnection));

            var halKitConfiguration = new HalKitConfiguration(configuration.ViagogoApiRootEndpoint)
            {
                CaptureSynchronizationContext = configuration.CaptureSynchronizationContext
            };

            Configuration = configuration;
            TokenStore    = tokenStore;
            Hypermedia    = new HalClient(halKitConfiguration, apiConnection);
            var linkFactory = new LinkFactory(configuration);

            OAuth2         = new OAuth2Client(oauthConnection, configuration);
            User           = new UserClient(Hypermedia);
            Search         = new SearchClient(Hypermedia);
            Addresses      = new AddressesClient(User, Hypermedia, linkFactory);
            Purchases      = new PurchasesClient(User, Hypermedia, linkFactory);
            Sales          = new SalesClient(Hypermedia, linkFactory);
            Shipments      = new ShipmentsClient(Hypermedia, linkFactory);
            PaymentMethods = new PaymentMethodsClient(User, Hypermedia, linkFactory);
            Countries      = new CountriesClient(Hypermedia, linkFactory);
            Currencies     = new CurrenciesClient(Hypermedia, linkFactory);
            Categories     = new CategoriesClient(Hypermedia, linkFactory);
            Events         = new EventsClient(Hypermedia);
            Listings       = new ListingsClient(Hypermedia);
            Venues         = new VenuesClient(Hypermedia);
            SellerListings = new SellerListingsClient(Hypermedia, linkFactory);
            Webhooks       = new WebhooksClient(Hypermedia, linkFactory);

            BatchClient = new BatchClient(apiConnection,
                                          new ApiResponseFactory(serializer, halKitConfiguration),
                                          serializer,
                                          new LinkResolver());
        }
        private async Task Given_ACountryInTheDatabase_When_GetCountryIsInvokedWithTheCountryId_Then_TheCountryIsReturned(Country country)
        {
            try
            {
                var countryReturned = await CountriesClient.GetCountry(country.Id);

                Assert.AreEqual(country.Alpha2Code, countryReturned.Alpha2Code);
                Assert.AreEqual(country.CreatedByUserId, countryReturned.CreatedByUserId);
                Assert.AreEqual(country.CreatedOn, countryReturned.CreatedOn);
                Assert.AreEqual(country.Id, countryReturned.Id);
                Assert.AreEqual(country.LastUpdatedByUserId, countryReturned.LastUpdatedByUserId);
                Assert.AreEqual(country.LastUpdatedOn, countryReturned.LastUpdatedOn);
                Assert.AreEqual(country.FullName, countryReturned.FullName);
                Assert.AreEqual(country.PhoneNumberRegex, countryReturned.PhoneNumberRegex);
                Assert.AreEqual(country.PostalCodeRegex, countryReturned.PostalCodeRegex);
            }
            catch (Exception e)
            {
                Assert.Fail($"{e.Message}\n{e.StackTrace}");
            }
        }
        private async Task <Country> Given_ACountry_When_CreateCountryIsInvoked_Then_TheCountryIsReturned()
        {
            var us = new Country
            {
                Alpha2Code      = TestData.UsCountryAlpha2Code,
                CreatedByUserId = TestData.CountryCreatedById,
                CreatedOn       = TestData.NonServiceGeneratedCountryCreatedOn,
                Id = TestData.NonServiceGeneratedCountryId,
                LastUpdatedByUserId = TestData.CountryLastUpdatedById,
                LastUpdatedOn       = TestData.NonServiceGeneratedCountryLastUpdatedOn,
                FullName            = TestData.UsCountryName,
                PhoneNumberRegex    = TestData.UsPhoneNumberRegex,
                PostalCodeRegex     = TestData.UsPostalCodeRegex
            };

            try
            {
                var usReturned = await CountriesClient.CreateCountry(us);

                Assert.AreEqual(TestData.UsCountryAlpha2Code, usReturned.Alpha2Code);
                Assert.AreEqual(TestData.CountryCreatedById, usReturned.CreatedByUserId);
                Assert.AreEqual(TestData.UsCountryName, usReturned.FullName);
                Assert.AreNotEqual(TestData.NonServiceGeneratedCountryCreatedOn, usReturned.CreatedOn);
                Assert.AreNotEqual(TestData.NonServiceGeneratedCountryId, usReturned.Id);
                Assert.IsNull(usReturned.LastUpdatedByUserId);
                Assert.IsNull(usReturned.LastUpdatedOn);
                Assert.AreEqual(TestData.UsPhoneNumberRegex, usReturned.PhoneNumberRegex);
                Assert.AreEqual(TestData.UsPostalCodeRegex, usReturned.PostalCodeRegex);

                us = usReturned;
            }
            catch (Exception e)
            {
                Assert.Fail($"{e.Message}\n{e.StackTrace}");
            }

            return(us);
        }
        private async Task Given_ACountryIdInTheDatabase_When_DeleteCountryIsInvokedWithTheCountryId_Then_TheCountryIsDeleted(int countryId)
        {
            try
            {
                await CountriesClient.DeleteCountry(countryId);

                var softDeletedAddress = await CountriesClient.GetCountry(countryId);

                Assert.IsTrue(softDeletedAddress.EffectiveEndDate > DateTime.UtcNow.AddSeconds(-5) && softDeletedAddress.EffectiveEndDate <= DateTime.UtcNow);

                var uri = new Uri(Path.Combine(ConfigurationManager.AppSettings[Constants.ApiEndpointKey], Routes.CountryV1BaseRoute, "force", countryId.ToString()));

                using (var client = new HttpClient())
                {
                    using (var response = await client.DeleteAsync(uri))
                    {
                        if (!response.IsSuccessStatusCode)
                        {
                            throw new HttpRequestException(response.Content.ToString());
                        }
                    }
                }
            }
            catch (HttpRequestException e)
            {
                Assert.Fail($"{e.Message}\n{e.StackTrace}");
            }

            try
            {
                await CountriesClient.GetCountry(countryId);

                Assert.Fail($"Address id: {countryId} was found after it should have been deleted.");
            }
            catch (ApiInvokerException)
            {
            }
        }
Пример #9
0
        public async Task <ActionResult> Index()
        {
            List <Countries> resp = await CountriesClient.GetCountriesAsync();

            return(View(resp));
        }
Пример #10
0
        public static bool UpdateMaster(DocumentsContext ctx, MFilesDocument targetDoc, ObjectVersionWrapper sourceDoc,
                                        IDictionary <string, VaultDetails> vaultDetails, CountriesClient countries)
        {
            targetDoc.Guid         = sourceDoc.Guid;
            targetDoc.CreatedDate  = sourceDoc.CreatedDate;
            targetDoc.ModifiedDate = sourceDoc.ModifiedDate;

            var masterDoc = targetDoc.Document;

            masterDoc.MFilesDocument = targetDoc;
            masterDoc.UnNumber       = string.IsNullOrEmpty(sourceDoc.UnNumber)?sourceDoc.Name:sourceDoc.UnNumber;
            masterDoc.Convention     = vaultDetails[sourceDoc.VaultName].NameInDb ?? sourceDoc.VaultName.ToLower();
            var authorAndType = GetAuthor(sourceDoc, countries);

            if (authorAndType != null)
            {
                masterDoc.Author     = authorAndType.Item1;
                masterDoc.AuthorType = authorAndType.Item2 ? "organization" : "person";
            }
            masterDoc.CountryFull = countries.GetCountryIsoCode2(sourceDoc.Country) != null ? sourceDoc.Country: null;
            masterDoc.Country     = countries.GetCountryIsoCode2(masterDoc.CountryFull);
            masterDoc.Copyright   = sourceDoc.Copyright;
            var period = sourceDoc.GetPeriod();

            if (period != null)
            {
                masterDoc.PeriodStartDate = period.Item1;
                masterDoc.PeriodEndDate   = period.Item2;
            }
            masterDoc.PublicationDate = sourceDoc.PublicationDate;

            lock ("Process") {
                ProcessDocumentTypes(ctx, masterDoc, sourceDoc);
                ProcessMeetings(ctx, masterDoc, sourceDoc);
                ProcessMeetingTypes(ctx, masterDoc, sourceDoc);
                ProcessChemicals(ctx, masterDoc, sourceDoc);
                ProcessPrograms(ctx, masterDoc, sourceDoc);
                ProcessTerms(ctx, masterDoc, sourceDoc);
                ProcessTags(ctx, masterDoc, sourceDoc);

                using (var trans = ctx.Database.BeginTransaction())
                {
                    try
                    {
                        ctx.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        ClassLogger.Error("SQL exception " + ex);
                        throw;
                    }
                }
            }
            return(true);
        }
Пример #11
0
        public static MFilesDocument CreateMaster(DocumentsContext ctx, ObjectVersionWrapper sourceDoc, IDictionary <string, VaultDetails> vaultDetails, CountriesClient coutries)
        {
            var targetDoc = ctx.MFilesDocuments.Create();

            ctx.MFilesDocuments.Add(targetDoc);

            var masterDoc = new Document {
                MFilesDocument = targetDoc
            };

            ctx.Documents.Add(masterDoc);

            UpdateMaster(ctx, targetDoc, sourceDoc, vaultDetails, coutries);
            return(targetDoc);
        }