public void MonthBetween()
 {
     DateTime min = new DateTime(2000, 11, 1);
     DateTime max = new DateTime(2000, 12, 2);
     DateTime result = new DateTimeGenerator(min, max).GetRandomValue();
     Assert.IsTrue(result.Month == 11 || result.Month == 12);
 }
 public void YearBetween()
 {
     DateTime min = new DateTime(2000, 11, 1);
     DateTime max = new DateTime(2001, 11, 1);
     DateTime result = new DateTimeGenerator(min, max).GetRandomValue();
     Assert.IsTrue(result.Year == 2000 || result.Year == 2001);
 }
 public void DayBetween()
 {
     DateTime min = new DateTime(2000, 11, 1);
     DateTime max = new DateTime(2000, 11, 2);
     DateTime result = new DateTimeGenerator(min, max).GetRandomValue();
     Assert.IsTrue(result.Day == 1 || result.Day == 2);
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            // Dependencies.
            IDateTimeGenerator       dateTimeGenerator        = new DateTimeGenerator();
            ITypeConverter           typeConverter            = new TypeConverter();
            ExternalMechanismFactory externalMechanismFactory = new ExternalMechanismFactory();

            SecureConnectionSettings connectionSettings = new SecureConnectionSettings(
                "raspberrypi",
                "/path/to/client/certificate.p12",
                "password");

            ExternalAuthConnectionFactory sslAuthConnectionFactory = new ExternalAuthConnectionFactory(
                "raspberrypi",
                externalMechanismFactory,
                connectionSettings);

            Settings producingSettings = new Settings("Journeys", "journey");

            // Generate journey message.
            Journey            journey = new Journey(150, 35.5, 121.3, "Weather was wet and windy.");
            IMessage <Journey> message = new Message <Journey>(dateTimeGenerator, journey);

            // Produce the message.
            using IMessageProducer messageProducer = new MessageProducer(sslAuthConnectionFactory, typeConverter);
            messageProducer.Produce(producingSettings, message);

            Console.WriteLine($"Message sent. ID: {message.Data.Id}");
            Console.ReadLine();
        }
Beispiel #5
0
        public void Generate_WhenPassedWithDateTime_ReturnsUtcString()
        {
            var testInput = new DateTime(2020, 02, 07, 10, 00, 00);
            var sut       = new DateTimeGenerator();
            var result    = sut.Generate(testInput);

            result.Should().Be("2020-02-07T10:00:00+00:00");
        }
Beispiel #6
0
 public void DateTimeGenerator_GenerateDateTime_50X_SUCCESS()
 {
     for (int i = 0; i < 50; i++)
     {
         DateTime generated = DateTimeGenerator.GenerateDateTime();
         Assert.NotEqual(new DateTime(), generated);
     }
 }
 public void FullyRestricted()
 {
     DateTime min = new DateTime(2000, 11, 1);
     DateTime max = new DateTime(2000, 11, 1);
     DateTime result = new DateTimeGenerator(min, max).GetRandomValue();
     Assert.AreEqual(2000, result.Year);
     Assert.AreEqual(11, result.Month);
     Assert.AreEqual(1, result.Day);
 }
Beispiel #8
0
        public void DateTimeGeneratorWithDefaultTest()
        {
            IGenerator <DateTime> dtg = new DateTimeGenerator();
            var checkme = (DateTime)dtg.Generate();
            var current = DateTime.Now;

            Assert.IsNotNull(checkme);
            Assert.That(checkme, Is.InRange(current.AddYears(-10), current.AddYears(10)));
        }
Beispiel #9
0
        public void DateTimeGeneratorWithOverrideValues()
        {
            var mymin = Convert.ToDateTime("1/1/1972");
            var mymax = Convert.ToDateTime("1/1/1980");

            IGenerator <DateTime> dtg = new DateTimeGenerator(mymin, mymax);
            var checkme = (DateTime)dtg.Generate();

            Assert.That(checkme, Is.InRange(mymin, mymax));
        }
Beispiel #10
0
        public void DateTimeGenerator_GenerateDateTime_ArgumentException_EqualDates()
        {
            var startDate = DateTime.Now;

            Exception ex = Assert.Throws <ArgumentException>(() =>
            {
                DateTime generated = DateTimeGenerator.GenerateDateTime(startDate, startDate);
            });

            Assert.StartsWith("Cannot generate a random date between do equal dates", ex.Message);
        }
        public void CreateWithNullContextDoesNotThrow()
        {
            // Fixture setup
#pragma warning disable 618
            var sut = new DateTimeGenerator();
#pragma warning restore 618
            // Exercise system and verify outcome
            var dummyRequest = new object();
            Assert.DoesNotThrow(() => sut.Create(dummyRequest, null));
            // Teardown
        }
        public void SutIsSpecimenBuilder()
        {
            // Fixture setup
            // Exercise system
#pragma warning disable 618
            var sut = new DateTimeGenerator();
#pragma warning restore 618
            // Verify outcome
            Assert.IsAssignableFrom <ISpecimenBuilder>(sut);
            // Teardown
        }
Beispiel #13
0
        public void DateTimeGenerator_GenerateDateTime_ArgumentException_MinMax()
        {
            var startDate = DateTime.Now;
            var endtDate  = startDate.AddYears(2);

            Exception ex = Assert.Throws <ArgumentException>(() =>
            {
                DateTime generated = DateTimeGenerator.GenerateDateTime(endtDate, startDate);
            });

            Assert.StartsWith("Minimum date should be lower than maximum date", ex.Message);
        }
Beispiel #14
0
        public void DateTimeGenerator_GenerateDateTime_Ranged_50X_SUCCESS()
        {
            var startDate = DateTime.Now;
            var endtDate  = startDate.AddYears(2);

            for (int i = 0; i < 50; i++)
            {
                DateTime generated = DateTimeGenerator.GenerateDateTime(startDate, endtDate);
                Assert.NotEqual(new DateTime(), generated);
                Assert.InRange(generated, startDate, endtDate);
            }
        }
        public void CreateWithNullRequestWillReturnCorrectResult()
        {
            // Fixture setup
#pragma warning disable 618
            var sut = new DateTimeGenerator();
#pragma warning restore 618
            // Exercise system
            var dummyContainer = new DelegatingSpecimenContext();
            var result         = sut.Create(null, dummyContainer);
            // Verify outcome
            Assert.Equal(new NoSpecimen(), result);
            // Teardown
        }
        public void GenerateWorks(int precision, int maxLength, DateTime value, string expected)
        {
            // Arrange
            var random = new Mock <IRandomNumber>();

            random.Setup(x => x.Next(It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(value);

            var sut = new DateTimeGenerator(random.Object, precision, maxLength);

            // Act
            var result = sut.Generate();

            // assert
            Assert.Equal(expected, result);
        }
        public void GenerateWorksWithOffset(DateTime value, TimeSpan offset, bool offsetPositive, string expected)
        {
            // Arrange
            var random = new Mock <IRandomNumber>();

            random.Setup(x => x.Next(It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(value);
            random.Setup(x => x.Next(new DateTime(1, 1, 1), new DateTime(1, 1, 1, 14, 0, 0))).Returns(new DateTime(1, 1, 1) + offset);
            random.Setup(x => x.Next(0, 1)).Returns(offsetPositive ? 1 : 0);

            var sut = new DateTimeGenerator(random.Object, 34, 10); // DateTimeOffset

            // Act
            var result = sut.Generate();

            // assert
            Assert.Equal(expected, result);
        }
        public void CreateWithDateTimeRequestReturnsCorrectResult()
        {
            // Fixture setup
            var before          = DateTime.Now;
            var dateTimeRequest = typeof(DateTime);

#pragma warning disable 618
            var sut = new DateTimeGenerator();
#pragma warning restore 618
            // Exercise system
            var dummyContext = new DelegatingSpecimenContext();
            var result       = sut.Create(dateTimeRequest, dummyContext);
            // Verify outcome
            var after = DateTime.Now;
            var dt    = Assert.IsAssignableFrom <DateTime>(result);
            Assert.True(before <= dt && dt <= after);
            // Teardown
        }
        private void BusVehicleSeed()
        {
            OperationDataContext context = new OperationDataContext();

            var bandung = new PlaceModel {
                Name = "Bandung"
            };
            var yogyakarta = new PlaceModel {
                Name = "Yogyakarta"
            };
            var curup = new PlaceModel {
                Name = "Curup"
            };
            var surabaya = new PlaceModel {
                Name = "Surabaya"
            };
            var denpasar = new PlaceModel {
                Name = "Denpasar"
            };

            var places = new List <PlaceModel>()
            {
                bandung, yogyakarta, curup, surabaya, denpasar
            };

            List <RouteModel> busRoutes = new List <RouteModel>();

            // Generate list of busRoute
            foreach (var origin in places)
            {
                foreach (var destination in places)
                {
                    if (origin != destination)
                    {
                        busRoutes.Add(new RouteModel {
                            OriginName = origin.Name, DestinationName = destination.Name
                        });
                    }
                }
            }

            if (context.Places.Count() == 0)
            {
                // Insert all places above to database
                foreach (var item in places)
                {
                    Place place = new Place()
                    {
                        Name = item.Name
                    };

                    context.Places.InsertOnSubmit(place);
                    context.SubmitChanges();
                }

                // Insert all busRoute to database
                foreach (var item in busRoutes)
                {
                    Route route = new Route()
                    {
                        Origin      = item.OriginName,
                        Destination = item.DestinationName
                    };

                    context.Routes.InsertOnSubmit(route);
                    context.SubmitChanges();
                }
            }

            if (context.BusVehicles.Count() == 0)
            {
                var dates  = DateTimeGenerator.GetDaysInRange(DateTime.Today, DateTime.Today.AddDays(60));
                var busses = new List <BusVehicleModel>();

                var busNames = new List <string>()
                {
                    "Primajasa", "MGI", "Budiman", "Putra Raflesia", "Lorena", "Haryanto"
                };
                var busClasses = AppConstants.BusClasses;

                foreach (DateTime date in dates)
                {
                    //var tes = date;
                    for (double i = 0; i < 24; i += 2)
                    {
                        foreach (var route in busRoutes)
                        {
                            int randName  = rand.Next(busNames.Count);
                            int randClass = rand.Next(busClasses.Count);

                            busses.Add(BusGenerator.GenerateBus(route,
                                                                date.AddHours(rand.Next(0, 24)).AddMinutes(rand.Next(0, 60)),
                                                                busNames[randName],
                                                                busClasses[randClass]));
                        }
                    }
                }

                // Insert all busvehicle to database
                // Belum bisa, masih ada errornya
                foreach (var item in busses)
                {
                    BusVehicle busVehicle = new BusVehicle()
                    {
                        Name          = item.Name,
                        Class         = item.Class,
                        DepartureTime = DateTime.Parse(item.DepartureTime),
                        RouteID       = item.RouteID
                    };

                    //context.BusVehicles.InsertOnSubmit(busVehicle);
                    //context.SubmitChanges();
                }
            }
        }
Beispiel #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DateTimeGeneratorFacts"/> class.
 /// </summary>
 public DateTimeGeneratorFacts()
 {
     this.cts     = new CancellationTokenSource();
     this.context = new GenerationContext(this.cts.Token);
     this.target  = new DateTimeGenerator();
 }
 public void ConcructorWithGoodPrecisionWorks(int precision, int maxLength)
 {
     // Arrange & Act & assert
     _ = new DateTimeGenerator(Mock.Of <IRandomNumber>(), precision, maxLength);
 }
        public void DateTimeGeneratorWithOverrideValues()
        {
            var mymin = Convert.ToDateTime("1/1/1972");
            var mymax = Convert.ToDateTime("1/1/1980");

            IGenerator<DateTime> dtg = new DateTimeGenerator(mymin, mymax);
            var checkme = (DateTime) dtg.Generate();
            Assert.That(checkme, Is.InRange(mymin, mymax));
        }
Beispiel #23
0
        protected override void Seed(TrainTicketsDbContext context)
        {
            var paris = new City {
                Name = "Paris", Id = Guid.Parse("280BB2E9-782A-42C9-875A-7DC0178452A6")
            };
            var brussels = new City {
                Name = "Brussels", Id = Guid.Parse("280BB2E9-782A-42C9-875A-7DC0178452A7")
            };
            var berlin = new City {
                Name = "Berlin", Id = Guid.Parse("280BB2E9-782A-42C9-875A-7DC0178452A8")
            };
            var amsterdam = new City {
                Name = "Amsterdam", Id = Guid.Parse("280BB2E9-782A-42C9-875A-7DC0178452A9")
            };
            var london = new City {
                Name = "London", Id = Guid.Parse("280BB2E9-782A-42C9-875A-7DC0178452AA")
            };

            var cities = new List <City>()
            {
                paris, brussels, berlin, amsterdam, london
            };

            List <TrainRoute> trainRoutes;

            if (context.Cities.Count() == 0)
            {
                context.Cities.AddOrUpdate(cities.ToArray());

                // TrainRoutes
                trainRoutes = new List <TrainRoute>()
                {
                    new TrainRoute {
                        Departure = paris, Arrival = brussels, Price = 20.0M
                    },
                    new TrainRoute {
                        Departure = paris, Arrival = amsterdam, Price = 30.0M
                    },
                    new TrainRoute {
                        Departure = paris, Arrival = berlin, Price = 50.0M
                    },
                    new TrainRoute {
                        Departure = paris, Arrival = london, Price = 40.0M
                    },

                    new TrainRoute {
                        Departure = brussels, Arrival = amsterdam, Price = 20.0M
                    },
                    new TrainRoute {
                        Departure = brussels, Arrival = berlin, Price = 40.0M
                    },
                    new TrainRoute {
                        Departure = brussels, Arrival = london, Price = 30.0M
                    },
                    new TrainRoute {
                        Departure = brussels, Arrival = paris, Price = 30.0M
                    },

                    new TrainRoute {
                        Departure = amsterdam, Arrival = london, Price = 30.0M
                    },
                    new TrainRoute {
                        Departure = amsterdam, Arrival = berlin, Price = 40.0M
                    },
                    new TrainRoute {
                        Departure = amsterdam, Arrival = paris, Price = 30.0M
                    },
                    new TrainRoute {
                        Departure = amsterdam, Arrival = brussels, Price = 20.0M
                    },

                    new TrainRoute {
                        Departure = london, Arrival = berlin, Price = 60.0M
                    },
                    new TrainRoute {
                        Departure = london, Arrival = paris, Price = 40.0M
                    },
                    new TrainRoute {
                        Departure = london, Arrival = amsterdam, Price = 30.0M
                    },
                    new TrainRoute {
                        Departure = london, Arrival = brussels, Price = 30.0M
                    },

                    new TrainRoute {
                        Departure = berlin, Arrival = london, Price = 60.0M
                    },
                    new TrainRoute {
                        Departure = berlin, Arrival = paris, Price = 50.0M
                    },
                    new TrainRoute {
                        Departure = berlin, Arrival = amsterdam, Price = 40.0M
                    },
                    new TrainRoute {
                        Departure = berlin, Arrival = brussels, Price = 40.0M
                    },
                };

                context.TrainRoutes.AddOrUpdate(trainRoutes.ToArray());
            }
            else
            {
                trainRoutes = context.TrainRoutes.ToList();
            }

            var dates  = DateTimeGenerator.GetDaysInRange(DateTime.Today, DateTime.Today.AddDays(60));
            var trains = new List <Train>();

            foreach (DateTime date in dates)
            {
                for (int i = 0; i < 24; i += 2)
                {
                    foreach (var route in trainRoutes)
                    {
                        trains.Add(TrainGenerator.GenerateTrain(route,
                                                                date.AddHours(i).AddMinutes(rand.Next(0, 60))));
                    }
                }
            }

            context.Trains.AddRange(trains);

            context.Configuration.AutoDetectChangesEnabled = false;
            context.Configuration.ValidateOnSaveEnabled    = false;
            context.SaveChanges();
        }
        public GeneratorOptions <T> Range(Expression <Func <T, DateTime> > propertyExpression, DateTime min, DateTime max)
        {
            var generator = new DateTimeGenerator(min, max);

            return(For(propertyExpression, generator));
        }
 public void DateTimeGeneratorWithDefaultTest()
 {
     IGenerator<DateTime> dtg = new DateTimeGenerator();
     var checkme = (DateTime) dtg.Generate();
     var current = DateTime.Now;
     Assert.IsNotNull(checkme);
     Assert.That(checkme, Is.InRange(current.AddYears(-10), current.AddYears(10)));
 }