Example #1
0
        public void DiseaseSimulatorClient_ReceiveAction()
        {
            // Arrange
            var nsEndpoint    = "tcp://127.0.0.1:55021";
            var mockLogger    = new Mock <ILogger>();
            var name          = "DSC1";
            var timeSimulator = new TimeSimulator()
            {
                IsReportingProgress = true
            };
            var client = new DiseaseSimulatorClient(name, nsEndpoint, mockLogger.Object)
            {
                TimeSimulator = timeSimulator
            };
            var mockRequestClient = new Mock <IRequestSocket>();

            client.RegClient.Socket = mockRequestClient.Object;
            var date       = new DateTime(2018, 1, 1);
            var mockClient = new Mock <IClient <ZFrame> >();

            client.Client = mockClient.Object;

            // Act
            client.ReceiveAction(new ZFrame());

            // Assert
            Assert.IsFalse(timeSimulator.IsReportingProgress);
        }
Example #2
0
        public void ReportActionConnectsAndSendsTest()
        {
            // Arrange
            var nsEndpoint        = "tcp://127.0.0.1:55021";
            var mockLogger        = new Mock <ILogger>();
            var name              = "DSC1";
            var timeSimulator     = new TimeSimulator();
            var random            = new Random();
            var generator         = new DiseaseRecordGenerator();
            var client            = new DiseaseSimulatorClient(name, nsEndpoint, mockLogger.Object);
            var mockRequestClient = new Mock <IRequestSocket>();

            client.RegClient.Socket = mockRequestClient.Object;
            var endpoint     = "tcp://127.0.0.1:55521"; // Added 1 to the end
            var reportAction = new ReportAction(client.SystemRegistration, timeSimulator, random, generator, client, endpoint);
            var date         = new DateTime(2018, 1, 1);
            var mockClient   = new Mock <IClient <ZFrame> >();

            client.Client = mockClient.Object;

            // Act
            reportAction.Action(date);

            // Assert
            mockClient.Verify(x => x.Connect(It.IsAny <string>()), Times.Once);
            mockClient.Verify(x => x.SendAsync(It.IsAny <string>(), It.IsAny <Action <ZFrame> >()), Times.Once);
        }
 public ReportAction(SystemRegistration systemRegistration,
                     TimeSimulator timeSimulator,
                     Random random,
                     DiseaseRecordGenerator generator,
                     DiseaseSimulatorClient client,
                     string endpoint)
 {
     SystemRegistration     = systemRegistration;
     TimeSimulator          = timeSimulator;
     Random                 = random;
     DiseaseGenerator       = generator;
     DiseaseSimulatorClient = client;
     Endpoint               = endpoint;
 }
Example #4
0
        public void TimeSimulatorStartTest()
        {
            // Arrange
            var timeSimulator = new TimeSimulator();
            int callCount     = 0;

            // Act
            timeSimulator.Start(DateTime.Now, 43200, 1, (DateTime d) =>
            {
                callCount++;
                timeSimulator.IsReportingProgress = false;
            });
            timeSimulator.Wait();

            // Assert
            Assert.IsTrue(callCount > 0 && callCount < 4, "There should be between 1 and 3 calls");
        }
Example #5
0
        internal static void Start()
        {
            var name          = Args.Value(Constants.Name);
            var nsEndpoint    = Args.Value(Constants.NameServerEndpoint);
            var timeSimulator = new TimeSimulator();

            int year           = Args.Value(Constants.Year).To <int>();
            int month          = Args.Value(Constants.Month).To <int>();
            int day            = Args.Value(Constants.Day).To <int>();
            int timeMultiplier = Args.Value(Constants.TimeMultiplier).To <int>();
            int duration       = Args.Value(Constants.Duration).To <int>();

            Logger = new LoggerClient(Args.Value(Constants.LoggerServerName), name, nsEndpoint);
            var client = new DiseaseSimulatorClient(name, nsEndpoint, Logger)
            {
                Client = new RequestClient(true, false)
            };

            Logger?.WriteLine($"{Constants.Year}: {year}", client.SystemRegistration.Id);
            Logger?.WriteLine($"{Constants.Month}: {month}", client.SystemRegistration.Id);
            Logger?.WriteLine($"{Constants.Day}: {day}", client.SystemRegistration.Id);
            Logger?.WriteLine($"{Constants.TimeMultiplier}: {timeMultiplier}", client.SystemRegistration.Id);
            Logger?.WriteLine($"{Constants.Duration}: {duration}", client.SystemRegistration.Id);

            Logger?.WriteLine($"{name} has started.");
            Console.WriteLine("Simulator: " + name);


            string endpoint = Args.Value(Constants.Endpoint);

            Logger?.WriteLine($"{Constants.Endpoint}: {endpoint}");

            var startDate = new DateTime(year, month, day);

            Logger?.WriteLine($"{Constants.StartDate}: {startDate.ToLongDateString()}");

            var reportAction = new ReportAction(client.SystemRegistration, timeSimulator, new Random(), new DiseaseRecordGenerator(), client, endpoint);

            timeSimulator.Start(startDate, timeMultiplier, duration, reportAction.Action);
            timeSimulator.Wait();
        }
Example #6
0
 public static void NextDayEvent(Company company)
 {
     TimeSimulator.NextDay(company);
     company.Refresh();
 }