/// <summary> /// Create an async logger. /// </summary> public AsyncFileLogger(LogFormatter logFormatter = null, string folderPath = @"logs", IDateTime dateTimeProvider = null, uint delay = 50) { if (logFormatter != null) { _logFormatter = logFormatter; } else { _logFormatter = DefaultLogFormatter; } if (dateTimeProvider != null) { _dateTimeProvider = dateTimeProvider; } else { _dateTimeProvider = new DateTimeWrapper(); } _delay = delay; _logDateTime = _dateTimeProvider.Now(); _folderPath = folderPath; _currentLogFilePath = BuildLogFilePath(); CreateDirectoryPath(); _writer = OpenLogFile(); _loggerTask = Task.Factory.StartNew(Start, TaskCreationOptions.LongRunning); }
public void AddRental(string title, string ssn) { #region checks if there are any movies that have expired due date List <MovieRental> expiredRentals = new List <MovieRental>(); foreach (var r in rentals) { if (r.socialSecurityNumber == ssn && r.dueDate < returnTime.Now()) // the now() is actually the method in the IDateTime interface { expiredRentals.Add(r); } } if (expiredRentals.Count > 0) { throw new MovieWithExpiredDateFoundException(); } #endregion if (rentals.Where(r => r.socialSecurityNumber == ssn).ToList().Count == 3) { throw new MaximumThreeMoviesToRentalException(); } if (rentals.Contains(rentals.Where(r => r.movieTitle == title).FirstOrDefault())) { throw new CantPossessTwoCopiesOfSameVideoException(); } else { MovieRental rental = new MovieRental(title, ssn, returnTime.Now().AddDays(3)); rentals.Add(rental); } }
private void InitRules() { //1: Om fordonet väger över 1000 kg så ska priset vara 1000 SEK //2: Om fordonet väger under 1000 kg så ska priset vara 500 SEK //4: Om fordonet är en Lastbil gäller inte regel 1 eller 2 utan då är det ett standardpris på 2000 SEK. //5: Priset för regel 1 och 2 gäller om fordonet är en personbil. AddMutation((price, vehicle) => { if (vehicle is ILarge) { return(2000); } return(vehicle.Weight < 1000 && !(vehicle is Bike) ? 500 : price); }); //3: Om fordonet kör igenom tullen efter klockan 18:00 och innan 06:00 så ska priset vara det ordinarie priset minus 50%. Detta gäller endast veckodagar. AddMutation( (price, vehicle) => _dateTime.Now().Hour < 19 && _dateTime.Now().Hour > 6 ? price : price * 0.5m); //7: Priserna 1-6 gäller endast veckordagar. Alla helger plus högtider vill gränsvakterna ha dubbelt betalt och därmed ökar priset med 100%. AddMutation( (price, vehicle) => _holiday.IsItHoliday() ? price * 2 : price); //6: Om fordonet är en motorcykel är det priset för regel 1 och 2, minus 30 %. AddMutation( (price, vehicle) => vehicle is Bike ? price * 0.7m : price); //8: Om fordonet är en miljöbil vilket både lastbil, motorcykel och personbil kan vara så är kostnaden att passera 0 SEK till HåkanHellström - Landet. ¨ AddMutation( (price, vehicle) => vehicle is IEnviromentFriendly ? 0m : price); }
public void AddRental(string movieTitle, string socialSecurityNumber) { var checkInput = _rentalses.Count(m => m.Title == movieTitle && m.SecurityNumber == socialSecurityNumber); var ch = _rentalses.Count(c => c.SecurityNumber == socialSecurityNumber); var checkTime = _rentalses.Any(t => t.DateTime < _datetime.Now()); string ssn = string.Format("{0:0000-00-00}", socialSecurityNumber); var valideSsn = Regex.IsMatch(socialSecurityNumber, ssn); if (checkInput == 1) { throw new CanNotRetSamMovieException(); } if (checkInput == 0) { if (checkTime) { throw new DueDatesMovieException(); } if (ch >= 3) { throw new CanNotRetMorThenThreeException(); } if (valideSsn) { Rentals r = new Rentals { Title = movieTitle, SecurityNumber = socialSecurityNumber, DateTime = _datetime.Now().AddDays(3) }; _rentalses.Add(r); } } }
public void WillGetAThreeDaysLaterDueDate() { datetime.Now().Returns(new DateTime(2017, 2, 12)); sut.AddRental("kalle", "5454545"); var result = sut.GetRentalsFor("5454545"); Assert.AreEqual(new DateTime(2017, 2, 15), result[0].due); }
public void Get_Three_Day_Later() { iDateTime.Now().Returns(new DateTime(2017 - 06 - 14)); sut.AddRental("Movie1", "20170101"); var result = sut.GetRentalsFor("20170101"); Assert.AreEqual(iDateTime.Now().AddDays(3), result[0].DateTime); }
public void CannotRentMovieWithPendingDate() { date.Now().Returns(new System.DateTime(2000, 1, 1)); sut.AddRental("Amor a quema ropa", "1979-01-01"); date.Now().Returns(new System.DateTime(2000, 1, 4)); Assert.Throws <RentalException>(() => sut.AddRental("Rambo", "1979-01-01")); }
public string GenerateFor(string userId) { var password = Guid.NewGuid().ToString(); var createdTime = _dateTime.Now(); var oneTimePassword = new OneTimePassword(password, createdTime); _storedUserPasswords.Add(userId, oneTimePassword); return(password); }
public static void WaitAnHour(IDateTime time) { //Incredibly wasteful - just to illustrate the point DateTime start = time.Now(); DateTime end = start + TimeSpan.FromHours(1); while (end < time.Now()) { ; } }
public void RentalsShudGetThreeDayLaterDueDate() { sut.AddRental(TestMovie.Title, TestCustomer.SSN); dateTime.Now().Returns(DateTime.Now.AddDays(3)); var dateTest = dateTime.Now(); var rentals = sut.GetRentalsFor(TestCustomer.SSN); Assert.AreEqual(dateTest.Year, rentals[0]._dueDate.Year); Assert.AreEqual(dateTest.Month, rentals[0]._dueDate.Month); Assert.AreEqual(dateTest.Day, rentals[0]._dueDate.Day); }
public void RentalsShudGetThreeDayLaterDueDate() { sut.AddRental("Die hard", "19880606"); dateTime.Now().Returns(DateTime.Now.AddDays(3)); var dateTest = dateTime.Now(); var rentals = sut.GetRentalsFor("19880606"); Assert.AreEqual(dateTest.Year, rentals[0]._dueDate.Year); Assert.AreEqual(dateTest.Month, rentals[0]._dueDate.Month); Assert.AreEqual(dateTest.Day, rentals[0]._dueDate.Day); }
public void CannotRentMovieIfCustomerHasAMovieWithExpiredDueDate() { Movie testMovie = new Movie("die hard"); var fakeDate = new DateTime(2017, 05, 12); dateTime.Now().Returns(fakeDate); // the datetime now will be the fakedate sut.AddRental(testVideo.Title, testCustomer.SocialSecurityNumber); dateTime.Now().Returns(fakeDate.AddDays(10)); Assert.Throws <MovieWithExpiredDateFoundException>(() => sut.AddRental(testMovie.Title, testCustomer.SocialSecurityNumber)); }
public void TestAddDaysCommand() { date = new CustomDateTime(); var expectedDate = DateTime.Now.Date; Assert.That(date.Now(), Is.EqualTo(expectedDate)); }
public static IObservable <DateTime> EverySecond(IDateTime dateTime) { return (Observable .Interval(TimeSpan.FromSeconds(1)) .Select(_ => dateTime.Now())); }
public void TestCustomDateTime_TimeNow() { var expected = DateTime.Now.Date; var actual = myTime.Now().Date; Assert.AreEqual(expected, actual); }
public void Setup() { date = Substitute.For <IDateTime>(); sut = new Rentals(date); date.Now().Returns(new System.DateTime(1222, 12, 12)); }
public ItemPriceLog() { CreatedAt = IDateTime.Now(); UpdatedAt = IDateTime.Now(); Date = IDateTime.Now(); Terminus = Environment.MachineName; }
public InventoryAdjustment() { CreatedAt = IDateTime.Now(); UpdatedAt = IDateTime.Now(); AdjustmentDate = IDateTime.Now(); Terminus = Environment.MachineName; }
protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity <Customer>().HasData( new Customer { CustomerId = Guid.NewGuid(), FullName = "Walkin Customer", Gender = Gender.Unknown, AmountOfLastDeposit = 0, CurrentBalance = 0, DateOfBirth = IDateTime.Now().AddYears(-50), CreatedAt = IDateTime.Now(), DateOfLastDeposit = IDateTime.Now(), OtherDetails = "Anonymous customer", Terminus = Environment.MachineName, UpdatedAt = IDateTime.Now(), } ); modelBuilder.Entity <Brand>().HasData(new Brand { Name = "Unknown", BrandId = Guid.NewGuid() }); modelBuilder.Entity <ItemCategory>().HasData(new ItemCategory { CategoryId = Guid.NewGuid(), Name = "Other", Description = "Other" }); modelBuilder.Entity <UnitOfMeasurement>().HasData(new UnitOfMeasurement { ID = Guid.NewGuid(), UOMCode = "Each", UOMDescription = "Each" }); base.OnModelCreating(modelBuilder); }
public ItemCategory() { CreatedAt = IDateTime.Now(); UpdatedAt = IDateTime.Now(); Terminus = Environment.MachineName; // CreatedBy = null; // UpdatedBy = null; }
public PaymentMethod() { CreatedAt = IDateTime.Now(); UpdatedAt = IDateTime.Now(); Terminus = Environment.MachineName; // CreatedBy = null; // UpdatedBy = null; }
public SalesOutlet() { CreatedAt = IDateTime.Now(); UpdatedAt = IDateTime.Now(); Terminus = Environment.MachineName; // CreatedBy = null; // UpdatedBy = null; }
public InvoiceLineItem() { CreatedAt = IDateTime.Now(); UpdatedAt = IDateTime.Now(); Terminus = Environment.MachineName; // CreatedBy = null; // UpdatedBy = null; }
public void Setup() { dateTime = Substitute.For <IDateTime>(); dateTime.Now().Returns(DateTime.Now); sut = new Rentals(dateTime); TestMovie = new Movie("Transporter", MovieGenre.Action); TestCustomer = new Customer("1978-06-14", "Olle Svensson"); }
public Staff() { CreatedAt = IDateTime.Now(); UpdatedAt = IDateTime.Now(); Terminus = Environment.MachineName; IsActive = true; // CreatedBy = null; // UpdatedBy = null; }
public UnitOfMeasurement() { ID = Guid.NewGuid(); CreatedAt = IDateTime.Now(); UpdatedAt = IDateTime.Now(); Terminus = Environment.MachineName; // CreatedBy = null; // UpdatedBy = null; }
public Customer() { CreatedAt = IDateTime.Now(); UpdatedAt = IDateTime.Now(); DateOfBirth = IDateTime.Now().AddYears(-20); Terminus = Environment.MachineName; // CreatedBy = null; // UpdatedBy = null; }
public Order() { CreatedAt = IDateTime.Now(); UpdatedAt = IDateTime.Now(); Terminus = Environment.MachineName; OrderDate = IDateTime.Now();; // CreatedBy = null; // UpdatedBy = null; }
public Item() { CreatedAt = IDateTime.Now(); UpdatedAt = IDateTime.Now(); Terminus = Environment.MachineName; VAT = 16; ReorderLevel = 5; IsActive = true; // CreatedBy = null; // UpdatedBy = null; }
internal Price ParsePrice(HtmlDocument doc) { var price = doc.DocumentNode.QuerySelector(".offer-price"); var priceValue = price?.Attributes["data-price"]?.Value; if (decimal.TryParse(priceValue, out var res)) { return(new Price(res, _dateTimeService.Now())); } return(null); }