public void ExitEarlyIfProfileIsMissing() { // Arrange AwsProfileRepositoryMock.Setup(x => x.Find(It.IsAny <Guid>())).Returns((AwsProfile)null); // Act Command.Execute(Guid.NewGuid(), "HoojeyId"); // Assert InstanceServiceMock.Verify(x => x.GetSecurityGroups(It.IsAny <AwsInstance>()), Times.Never); }
public void SkipsMissingProfile() { // Arrange Guid profileId = Guid.NewGuid(); AwsProfileRepositoryMock.Setup(x => x.Find(profileId)).Returns((AwsProfile)null); var command = new UpdateBillingData(AwsClientFactory, AwsProfileRepository, BillingManager, Clock, new S3PathParser()); // Act command.LoadDeltas(profileId); // Assert AwsClientFactoryMock.Verify(x => x.GetClient(It.IsAny <AwsProfile>()), Times.Never); }
public void ExitEarlyIfInstanceIdIsNotAtAmazon() { // Arrange var profile = new AwsProfile(); AwsProfileRepositoryMock.Setup(x => x.Find(profile.Id)).Returns(profile); InstanceServiceMock.Setup(x => x.GetInstance(It.IsAny <string>())).Returns((AwsInstance)null); AwsClientFactoryMock.Setup(x => x.GetClient(profile).InstanceService).Returns(InstanceServiceMock.Object); // Act Command.Execute(profile.Id, "HoojeyId"); // Assert InstanceServiceMock.Verify(x => x.GetSecurityGroups(It.IsAny <AwsInstance>()), Times.Never); }
public void SkipsProfilesWithoutBillingHistory() { // Arrange Guid profileId = Guid.NewGuid(); var profile = new AwsProfile { Id = profileId, DetailedBillingS3Bucket = "my-bucket", IsBillingHistoryLoaded = false }; AwsProfileRepositoryMock.Setup(x => x.Find(profileId)).Returns(profile); var command = new UpdateBillingData(AwsClientFactory, AwsProfileRepository, BillingManager, Clock, new S3PathParser()); // Act command.LoadDeltas(profileId); // Assert AwsProfileRepositoryMock.Verify(x => x.Update(It.IsAny <AwsProfile>()), Times.Never); }
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 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) )); }