示例#1
0
        public void PassTheCorrectMeetingLengthHoursToTheStrategy()
        {
            var container = new ServiceCollection();

            var strategy = new Mock <ICateringStrategy>();

            container.AddSingleton <ICateringStrategy>(strategy.Object);

            var repo     = new Mock <IMeetingRepository>();
            var meeting  = new MeetingBuilder().Random().NumberOfDays(1).Build();
            var meetings = new Meeting[] { meeting };

            repo.Setup(r => r.GetMeetings(It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(meetings);
            container.AddSingleton <IMeetingRepository>(repo.Object);

            var target = new Catering.Business.Engine(container.BuildServiceProvider());

            target.CreateData(DateTime.MinValue, DateTime.MaxValue);

            var expected = meeting.LengthHours;

            strategy.Verify(s => s.ShouldMeetingBeCatered(
                                It.IsAny <DateTime>(),
                                It.Is <float>(p => p == expected)
                                ), Times.Once);
        }
        static void Main(string[] args)
        {
            var container = new ServiceCollection();

            container.AddSingleton <IMeetingRepository>(c => new Catering.Data.MeetingServiceClient.Repository());
            container.AddSingleton <ICateringStrategy>(c => new Catering.Business.Strategy.Engine());

            var engine = new Catering.Business.Engine(container.BuildServiceProvider());

            engine.CreateData();
        }
示例#3
0
        public void PassTheLastDayOfNextMonthAsTheEndDateToTheMeetingRepository()
        {
            var container = new ServiceCollection();

            var repo = new Mock <IMeetingRepository>();

            container.AddInstance <IMeetingRepository>(repo.Object);

            var target = new Catering.Business.Engine(container.BuildServiceProvider());

            target.CreateData();

            repo.Verify(r => r.GetMeetings(It.IsAny <DateTime>(), DateTime.Now.LastDayOfNextMonth()), Times.Once);
        }
示例#4
0
        public void RetrieveTheMeetingsFromTheMeetingRepositoryExactlyOnce()
        {
            var container = new ServiceCollection();

            var repo = new Mock <IMeetingRepository>();

            container.AddInstance <IMeetingRepository>(repo.Object);

            var target = new Catering.Business.Engine(container.BuildServiceProvider());

            target.CreateData();

            repo.Verify(r => r.GetMeetings(It.IsAny <DateTime>(), It.IsAny <DateTime>()), Times.Exactly(1));
        }
示例#5
0
        public void PassTheCorrectDateAsTheEndDateToTheMeetingRepository()
        {
            var expected  = DateTime.Now.GetRandom();
            var container = new ServiceCollection();

            var repo = new Mock <IMeetingRepository>();

            container.AddSingleton <IMeetingRepository>(repo.Object);

            var target = new Catering.Business.Engine(container.BuildServiceProvider());

            target.CreateData(DateTime.MinValue, expected);

            repo.Verify(r => r.GetMeetings(It.IsAny <DateTime>(), expected), Times.Once);
        }
示例#6
0
        public void CallTheCateringStrategyOncePerMeetingDay()
        {
            var container = new ServiceCollection();

            var strategy = new Mock <ICateringStrategy>();

            container.AddSingleton <ICateringStrategy>(strategy.Object);

            var repo     = new Mock <IMeetingRepository>();
            var meetings = (null as IEnumerable <Meeting>).Create();

            repo.Setup(r => r.GetMeetings(It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(meetings);
            container.AddSingleton <IMeetingRepository>(repo.Object);

            var target = new Catering.Business.Engine(container.BuildServiceProvider());

            target.CreateData(DateTime.MinValue, DateTime.MaxValue);

            int expected = meetings.Sum(m => m.NumberOfDays);

            strategy.Verify(s => s.ShouldMeetingBeCatered(It.IsAny <DateTime>(), It.IsAny <float>()), Times.Exactly(expected));
        }
示例#7
0
        static void Main(string[] args)
        {
            var argumentPairs = new ArgumentCollection(args);

            // Get the start date specified in arguments or default to the 1st day of next month
            DateTime startDate = DateTime.Now.FirstDayOfNextMonth();

            if (argumentPairs.ContainsKey("-sd"))
            {
                startDate = DateTime.Parse(argumentPairs["-sd"]);
            }

            // Get the end date specified in arguments or default to the last day of next month
            DateTime endDate = DateTime.Now.LastDayOfNextMonth();

            if (argumentPairs.ContainsKey("-ed"))
            {
                endDate = DateTime.Parse(argumentPairs["-ed"]);
            }

            // Add dependencies to container
            var container = new ServiceCollection();

            // Source Data Repository -- Meeting Service
            container.AddSingleton <IMeetingRepository>(c =>
                                                        new Catering.Data.MeetingServiceClient.Repository());

            // Catering Strategy Logic
            container.AddSingleton <ICateringStrategy>(c =>
                                                       new Catering.Business.Strategy.Engine());


            // Call the orchestration logic
            var engine = new Catering.Business.Engine(container.BuildServiceProvider());

            engine.CreateData(startDate, endDate);
        }