Exemple #1
0
        public void ConstructiorMessageBusNullTest()
        {
            IPersonAdditionalInfoProvider provider = Mock.Create <IPersonAdditionalInfoProvider>();
            ILogger logger = GetLoggerMocked();

            Assert.ThrowsException <ArgumentNullException>(() => new PersonAdditionalInfoManager(provider, logger, null));
        }
Exemple #2
0
        public void ConstructiorMEssageBusIsSetProperly()
        {
            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = this.GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManagerFake(providerMock, logger, messageBus);

            Assert.AreSame(messageBus, manager.ExposedMessageBus);
        }
Exemple #3
0
        public void GetAnswersTypeByIdInvalidIdTest(int id)
        {
            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = this.GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManager(providerMock, logger, messageBus);

            Assert.ThrowsException <ApplicationException>(() => manager.GetAnswerTypeById(id));
        }
Exemple #4
0
        public void GetCountryByIdIncorrectTest(int id)
        {
            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = this.GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManager(providerMock, logger, messageBus);

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => manager.GetCountryById(id));
        }
Exemple #5
0
        public void ConstructiorDicionaryByNameInitialized()
        {
            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManagerFake(providerMock, logger, messageBus);

            Assert.IsNotNull(manager.ExposedAnswerTypeDictionaryByName);
        }
Exemple #6
0
        public void ConstructiorDicionaryByNameFilled()
        {
            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManagerFake(providerMock, logger, messageBus);

            // Mock.Assert(() => providerMock.GetAllAnswerTypes(), Occurs.Once());
            Assert.AreEqual(NUMBER_OF_ANSWER_TYPES, manager.ExposedAnswerTypeDictionaryByName.Keys.Count);
        }
Exemple #7
0
        public void GetAnswersTypeByNameInvaliNameTest()
        {
            string name = "abc";

            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = this.GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManager(providerMock, logger, messageBus);

            Assert.ThrowsException <ApplicationException>(() => manager.GetAnswerTypeByName(name));
        }
Exemple #8
0
        public void GetAllAnswersTypesTest()
        {
            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManager(providerMock, logger, messageBus);

            IEnumerable <AnswerType> result = manager.GetAllAnswerTypes();

            Assert.IsNotNull(result);
            Assert.AreEqual(NUMBER_OF_ANSWER_TYPES, result.Count());
        }
Exemple #9
0
        public void RequestByIdCallProviderByIdTest()
        {
            int id = 2;

            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = this.GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManagerFake(providerMock, logger, messageBus);

            Country result = manager.GetCountryById(id);

            Mock.Assert(() => providerMock.GetCountryById(Arg.AnyInt), Occurs.Once());
        }
Exemple #10
0
        public void RequestByNameCallProviderByNameTest()
        {
            string name = VALID_COUNTRY_NAME;

            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = this.GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManagerFake(providerMock, logger, messageBus);

            Country result = manager.GetCountryByName(name);

            Mock.Assert(() => providerMock.GetCountryByName(Arg.AnyString), Occurs.Once());
        }
Exemple #11
0
        public void GetCountryByIdInvalidIdTest(int id)
        {
            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = this.GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManagerFake(providerMock, logger, messageBus);

            Country result = manager.GetCountryById(id);

            Assert.IsNull(result);

            Assert.AreEqual(0, manager.ExposedCountryDictionaryById.Count);
        }
Exemple #12
0
        // [DataRow(VALID_NAME, VALID_NAME.ToUpper(), DisplayName = "Uppercase Name")]
        // [DataRow(VALID_NAME, VALID_NAME.ToLower(), DisplayName = "Lowercase Name")]
        public void GetAnswersTypeByNameTest(string name, string inputName)
        {
            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = this.GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManager(providerMock, logger, messageBus);

            AnswerType result = manager.GetAnswerTypeByName(inputName);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id > 0);
            Assert.AreEqual(name, result.Name);
        }
Exemple #13
0
        public void GetAnswersTypeByIdTest(int id)
        {
            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManager(providerMock, logger, messageBus);

            AnswerType result = manager.GetAnswerTypeById(id);

            Assert.IsNotNull(result);
            Assert.AreEqual(id, result.Id);
            Assert.IsNotNull(result.Name);
        }
Exemple #14
0
        public void GetCountryByNameInvalidNameTest()
        {
            string name = "abc";

            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = this.GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManagerFake(providerMock, logger, messageBus);

            Country result = manager.GetCountryByName(name);

            Assert.IsNull(result);

            Assert.AreEqual(0, manager.ExposedCountryDictionaryByName.Count);
        }
Exemple #15
0
        public void GetCountryByNameTest(string name, string inputName)
        {
            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = this.GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManagerFake(providerMock, logger, messageBus);

            Country result = manager.GetCountryByName(inputName);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id > 0);
            Assert.AreEqual(name, result.Name);

            Assert.AreEqual(1, manager.ExposedCountryDictionaryByName.Count);
        }
Exemple #16
0
        public void GetCountryByNameLowerCaseTest()
        {
            string validName = string.Format(COUNTRY_NAME_TEMPLATE, 3);
            string name      = validName.ToLower();

            IPersonAdditionalInfoProvider providerMock = this.GetPersonAdditionalInfoProviderMock();
            ILogger     logger     = this.GetLoggerMocked();
            IMessageBus messageBus = GetMessageBusMocked();
            var         manager    = new PersonAdditionalInfoManagerFake(providerMock, logger, messageBus);

            Country result = manager.GetCountryByName(name);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id > 0);
            Assert.AreEqual(validName, result.Name);

            Assert.AreEqual(1, manager.ExposedCountryDictionaryByName.Count);
        }
Exemple #17
0
        public PersonAdditionalInfoManager(IPersonAdditionalInfoProvider provider, ILogger logger, IMessageBus messageBus)
        {
            ParameterValidation.IsNotNull(provider, nameof(provider));
            ParameterValidation.IsNotNull(logger, nameof(logger));
            ParameterValidation.IsNotNull(messageBus, nameof(messageBus));

            this.provider   = provider;
            this.logger     = logger;
            this.messageBus = messageBus;

            this.answerTypesById = new Lazy <ConcurrentDictionary <int, AnswerType> >(() =>
            {
                IDictionary <int, AnswerType> answerTypes = this.provider.GetAllAnswerTypes().ToDictionary(p => p.Id);
                return(new ConcurrentDictionary <int, AnswerType>(answerTypes));
            });

            this.answerTypesByName = new Lazy <ConcurrentDictionary <string, AnswerType> >(() =>
            {
                IDictionary <string, AnswerType> answerTypes = this.provider.GetAllAnswerTypes().ToDictionary(p => p.Name);
                return(new ConcurrentDictionary <string, AnswerType>(answerTypes, StringComparer.OrdinalIgnoreCase));
            });

            this.ethnicitiesById = new Lazy <ConcurrentDictionary <int, Ethnicity> >(() =>
            {
                IDictionary <int, Ethnicity> ethnicities = this.provider.GetAllEthnicities().ToDictionary(e => e.Id);
                return(new ConcurrentDictionary <int, Ethnicity>(ethnicities));
            });

            this.ethnicitiesByName = new Lazy <ConcurrentDictionary <string, Ethnicity> >(() =>
            {
                IDictionary <string, Ethnicity> ethnicities = this.provider.GetAllEthnicities().ToDictionary(e => e.Name);
                return(new ConcurrentDictionary <string, Ethnicity>(ethnicities, StringComparer.OrdinalIgnoreCase));
            });

            this.orientationsById = new Lazy <ConcurrentDictionary <int, Orientation> >(() =>
            {
                IDictionary <int, Orientation> orientations = this.provider.GetAllOrientations().ToDictionary(o => o.Id);
                return(new ConcurrentDictionary <int, Orientation>(orientations));
            });

            this.orientationsByName = new Lazy <ConcurrentDictionary <string, Orientation> >(() =>
            {
                IDictionary <string, Orientation> orientations = this.provider.GetAllOrientations().ToDictionary(o => o.Name);
                return(new ConcurrentDictionary <string, Orientation>(orientations, StringComparer.OrdinalIgnoreCase));
            });

            this.unitsById = new Lazy <ConcurrentDictionary <int, Unit> >(() =>
            {
                IDictionary <int, Unit> units = this.provider.GetAllUnits().ToDictionary(u => u.Id);
                return(new ConcurrentDictionary <int, Unit>(units));
            });
            this.unitsByName = new Lazy <ConcurrentDictionary <string, Unit> >(() =>
            {
                IDictionary <string, Unit> units = this.provider.GetAllUnits().ToDictionary(u => u.Name);
                return(new ConcurrentDictionary <string, Unit>(units, StringComparer.OrdinalIgnoreCase));
            });

            this.countriesById   = new ConcurrentDictionary <int, Country>();
            this.countriesByName = new ConcurrentDictionary <string, Country>(StringComparer.OrdinalIgnoreCase);

            this.messageBus.Attach(typeof(Country), this.HandleMessageCountry);
        }
 public PersonAdditionalInfoManagerFake(IPersonAdditionalInfoProvider provider, ILogger logger, IMessageBus messageBus)
     : base(provider, logger, messageBus)
 {
 }