public void GetNextStop_ServerInNonCentralTimeZone_Ok() { // Arrange var stack = new Stack { ScheduleId = Guid.NewGuid() }; var schedule = new Schedule { Id = stack.ScheduleId, StopCron = "* 18 * * 1-5" }; ScheduleRepositoryMock.Setup(x => x.Find(schedule.Id)).Returns(schedule); var oneOClockEastern = new DateTime(2015, 10, 1, 13, 0, 0); var easternTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); oneOClockEastern = TimeZoneInfo.ConvertTime(oneOClockEastern, easternTimeZone); ClockMock.Setup(x => x.Now).Returns(oneOClockEastern); // == 2 PM central var expected = new TimeSpan(4, 0, 0); // Act var result = Calculator.GetNextStop(stack); // Assert result.Should().Be(expected); }
public void LoadsCsv() { // Arrange Guid profileId = Guid.NewGuid(); var profile = new AwsProfile { Id = profileId, DetailedBillingS3Bucket = "my-bucket", IsBillingHistoryLoaded = true, Account = "12345", }; AwsProfileRepositoryMock.Setup(x => x.Find(profileId)).Returns(profile); AwsClientFactoryMock.Setup(x => x.GetClient(profile)).Returns(AwsClientMock.Object); var storage = new TestStorageService(); AwsClientMock.Setup(x => x.StorageService).Returns(storage); storage.Contents = new MemoryStream(Resources.LineItemsZip); var now = new DateTime(2014, 6, 14, 16, 15, 14, DateTimeKind.Utc); ClockMock.Setup(x => x.UtcNow).Returns(now); var command = new UpdateBillingData(AwsClientFactory, AwsProfileRepository, BillingManager, Clock, new S3PathParser()); string loadedPeriod = null; LineItem lineItem = null; BillingManagerMock.Setup(x => x.LoadLineItems(It.IsAny <IEnumerable <LineItem> >(), It.IsAny <string>())) .Callback((IEnumerable <LineItem> lineItems, string period) => { lineItem = lineItems.FirstOrDefault(); loadedPeriod = period; }); // Act command.LoadDeltas(profileId); // Assert loadedPeriod.Should().Be("2014-06"); lineItem.RecordId.Should().Be("31861622192480759163092020", "should match first line item from line-items.csv embedded resource"); }
public void GetNextStop_Ok() { // Arrange var stack = new Stack { ScheduleId = Guid.NewGuid() }; var schedule = new Schedule { Id = stack.ScheduleId, StopCron = "* 18 * * 1-5" }; ScheduleRepositoryMock.Setup(x => x.Find(schedule.Id)).Returns(schedule); ClockMock.Setup(x => x.Now).Returns(new DateTime(2015, 10, 1, 17, 0, 0)); var expected = new TimeSpan(1, 0, 0); // Act var result = Calculator.GetNextStop(stack); // Assert result.Should().Be(expected); }
public void QueriesCorrectS3Object() { // Arrange Guid profileId = Guid.NewGuid(); var lastModified = new DateTime(2014, 6, 14, 13, 12, 11, DateTimeKind.Utc); var profile = new AwsProfile { Id = profileId, DetailedBillingS3Bucket = "my-bucket", Account = "12345", IsBillingHistoryLoaded = true, BillingMetadata = { { "2014-06", new BillingMetadata { LastModified = lastModified } } } }; AwsProfileRepositoryMock.Setup(x => x.Find(profileId)).Returns(profile); AwsClientFactoryMock.Setup(x => x.GetClient(profile)).Returns(AwsClientMock.Object); var storage = new TestStorageService(); AwsClientMock.Setup(x => x.StorageService).Returns(storage); var now = new DateTime(2014, 6, 14, 16, 15, 14, DateTimeKind.Utc); ClockMock.Setup(x => x.UtcNow).Returns(now); var command = new UpdateBillingData(AwsClientFactory, AwsProfileRepository, BillingManager, Clock, new S3PathParser()); // Act command.LoadDeltas(profileId); // Assert string expectedUrl = UpdateBillingData.MonthlyCsvUrl.Create("my-bucket", "12345", "2014-06"); storage.S3Url.Should().Be(expectedUrl); storage.LastModified.Should().Be(lastModified); storage.CallCount.Should().Be(1); }
public void SetsLastModified() { // Arrange Guid profileId = Guid.NewGuid(); var profile = new AwsProfile { Id = profileId, DetailedBillingS3Bucket = "my-bucket", IsBillingHistoryLoaded = true, Account = "12345", }; AwsProfileRepositoryMock.Setup(x => x.Find(profileId)).Returns(profile); AwsClientFactoryMock.Setup(x => x.GetClient(profile)).Returns(AwsClientMock.Object); var now = new DateTime(2014, 6, 14, 16, 15, 14, DateTimeKind.Utc); ClockMock.Setup(x => x.UtcNow).Returns(now); var storage = new TestStorageService(); AwsClientMock.Setup(x => x.StorageService).Returns(storage); storage.NewLastModified = new DateTime(2020, 1, 1, 1, 1, 1, DateTimeKind.Utc); storage.Contents = new MemoryStream(Resources.LineItemsZip); var command = new UpdateBillingData(AwsClientFactory, AwsProfileRepository, BillingManager, Clock, new S3PathParser()); // Act command.LoadDeltas(profileId); // Assert AwsProfileRepositoryMock.Verify( x => x.Update(It.Is((AwsProfile p) => p.Id == profileId && p.BillingMetadata["2014-06"].LastModified == storage.NewLastModified) )); }