private VmServiceProducer CreateModel(ProvisionTypeEnum provisionType, string organizationId, string additionalInformation)
        {
            var producer = new VmServiceProducer
            {
                ProvisionType         = CacheManager.TypesCache.Get <ProvisionType>(provisionType.ToString()),
                AdditionalInformation = new Dictionary <string, string>()
                {
                    { "fi", additionalInformation }
                }
            };

            if (provisionType == ProvisionTypeEnum.SelfProduced)
            {
                producer.SelfProducers = string.IsNullOrEmpty(organizationId)
                    ? new List <Guid>()
                    : new List <Guid> {
                    Guid.Parse(organizationId)
                };
            }
            else
            {
                producer.Organization = string.IsNullOrEmpty(organizationId)
                    ? (Guid?)null
                    : Guid.Parse(organizationId);
            }

            return(producer);
        }
        public void TranslateToEntityTest(string name)
        {
            var model = new VmServiceProducer {
                AdditionalInformation = new Dictionary <string, string>()
                {
                    { "fi", name }
                }
            };
            var toTranslate = new List <VmServiceProducer> {
                model
            };

            var translations = RunTranslationModelToEntityTest <VmServiceProducer, ServiceProducerAdditionalInformation>(translators, toTranslate, unitOfWorkMockSetup.Object);
            var translation  = translations.First();

            Assert.Equal(toTranslate.Count, translations.Count);
            CheckTranslation(model, translation);
        }
 private void CheckTranslation(VmServiceProducer source, ServiceProducerAdditionalInformation target)
 {
     target.LocalizationId.Should().NotBe(Guid.Empty);
     target.LocalizationId.Should().Be(LanguageCode.fi.ToString().GetGuid());
     target.Text.Should().Be(source.AdditionalInformation["fi"]);
 }
        private void CheckTranslation(ProvisionTypeEnum provisionType, VmServiceProducer source, ServiceProducer target)
        {
            target.Id.Should().NotBe(Guid.Empty);
            target.ProvisionTypeId.Should().Be(source.ProvisionType);
            switch (provisionType)
            {
            case ProvisionTypeEnum.SelfProduced:
                target.AdditionalInformations.Count.Should().Be(0);
                target.Organizations.Count.Should().Be(source.SelfProducers.Count);
                if (source.SelfProducers.Count > 0)
                {
                    target.Organizations.First().OrganizationId.Should().Be(source.SelfProducers.First());
                }
                break;

            case ProvisionTypeEnum.PurchaseServices:
                if (source.Organization.HasValue)
                {
                    target.Organizations.Count.Should().Be(1);
                    target.Organizations.First().OrganizationId.Should().Be(source.Organization.Value);
                }
                else
                {
                    target.Organizations.Should().BeEmpty();
                }

                if (string.IsNullOrEmpty(source.AdditionalInformation["fi"]))
                {
                    target.AdditionalInformations.Should().BeEmpty();
                }
                else
                {
                    var ai = target.AdditionalInformations.FirstOrDefault();
                    ai.Should().NotBeNull();
                    ai.Text.Should().Be(source.AdditionalInformation["fi"]);
                    ai.LocalizationId.Should().Be(LanguageCode.fi.ToString().GetGuid());
                }
                break;

            case ProvisionTypeEnum.Other:
                if (source.Organization.HasValue)
                {
                    target.Organizations.Count.Should().Be(1);
                    target.Organizations.First().OrganizationId.Should().Be(source.Organization.Value);
                    target.AdditionalInformations.Should().BeEmpty();
                }
                else if (!string.IsNullOrEmpty(source.AdditionalInformation["fi"]))
                {
                    target.Organizations.Should().BeEmpty();
                    var ai = target.AdditionalInformations.FirstOrDefault();
                    ai.Should().NotBeNull();
                    ai.Text.Should().Be(source.AdditionalInformation["fi"]);
                    ai.LocalizationId.Should().Be(LanguageCode.fi.ToString().GetGuid());
                }
                else
                {
                    target.Organizations.Should().BeEmpty();
                    target.AdditionalInformations.Should().BeEmpty();
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(provisionType), provisionType, null);
            }
        }