コード例 #1
0
        public void TestCommonCase()
        {
            var averageKeeperFactory = new AverageKeeperFactoryMock();
            var keeper = averageKeeperFactory.Instance;
            var selectorByCountryAndAge = new SelectorByCountryAndAgeMock();
            var singleAverageGetter     = new SingleAverageGetter(averageKeeperFactory, selectorByCountryAndAge);

            var source  = GenerateStorage;
            var age     = 20;
            var country = "USA";

            var result = singleAverageGetter.Calculate(source, age, country);

            Assert.Equal(1, selectorByCountryAndAge.RequestsCount);
            Assert.True(selectorByCountryAndAge.LastRequestedSource.SequenceEqual(source));
            Assert.Equal(age, selectorByCountryAndAge.LastRequestedAge);
            Assert.Equal(country, selectorByCountryAndAge.LastRequestedCountry);
            Assert.True(keeper.LastRequestedAnswer.HasValue);
            Assert.Equal(result, keeper.LastRequestedAnswer.Value);
            Assert.Equal(1, keeper.RequestsCount);
            Assert.True(keeper.IncomingValues.SequenceEqual(new List <double>()
            {
                2000, 2500, 1500
            }));
        }
コード例 #2
0
        public void TestNotRequestedResult()
        {
            var averageKeeperFactory = new AverageKeeperFactoryMock();
            var keeper = averageKeeperFactory.Instance;
            var selectorByCountryAndAge = new SelectorByCountryAndAgeMock();
            var singleAverageGetter     = new SingleAverageGetter(averageKeeperFactory, selectorByCountryAndAge);


            Assert.Equal(0, selectorByCountryAndAge.RequestsCount);
            Assert.True(selectorByCountryAndAge.LastRequestedSource == default(IEnumerable <Person>));
            Assert.False(selectorByCountryAndAge.LastRequestedAge.HasValue);
            Assert.True(string.IsNullOrEmpty(selectorByCountryAndAge.LastRequestedCountry));
            Assert.False(keeper.LastRequestedAnswer.HasValue);
            Assert.Equal(0, keeper.RequestsCount);
            Assert.False(keeper.IncomingValues.Any());
        }