public async Task Save_overwrites_memento_blob_if_already_exists() { // Arrange var userId = Guid.NewGuid(); FakeUserMemento oldMemento = fixture.Create <FakeUserMemento>(); CloudBlockBlob blob = s_container.GetBlockBlobReference( AzureMementoStore.GetMementoBlobName <FakeUser>(userId)); await blob.UploadTextAsync(serializer.Serialize(oldMemento)); FakeUserMemento memento = fixture.Create <FakeUserMemento>(); // Act Func <Task> action = () => sut.Save <FakeUser>(userId, memento, CancellationToken.None); // Assert action.ShouldNotThrow(); blob.Exists().Should().BeTrue(); using (Stream s = await blob.OpenReadAsync()) using (var reader = new StreamReader(s)) { string json = await reader.ReadToEndAsync(); object actual = serializer.Deserialize(json); actual.Should().BeOfType <FakeUserMemento>(); actual.ShouldBeEquivalentTo(memento); } }
public void TestInitialize() { if (s_storageEmulatorConnected == false) { Assert.Inconclusive("Could not connect to Azure Storage Emulator. See the output for details. Refer to the following URL for more information: http://go.microsoft.com/fwlink/?LinkId=392237"); } fixture = new Fixture().Customize(new AutoMoqCustomization()); serializer = new JsonMessageSerializer(); sut = new AzureMementoStore(s_container, serializer); }
public async Task Delete_deletes_memento_blob() { var userId = Guid.NewGuid(); FakeUserMemento memento = fixture.Create <FakeUserMemento>(); await sut.Save <FakeUser>(userId, memento, CancellationToken.None); await sut.Delete <FakeUser>(userId, CancellationToken.None); CloudBlockBlob blob = s_container.GetBlockBlobReference( AzureMementoStore.GetMementoBlobName <FakeUser>(userId)); blob.Exists().Should().BeFalse(); }
public async Task Save_sets_ContentType_to_application_json() { var userId = Guid.NewGuid(); FakeUserMemento memento = fixture.Create <FakeUserMemento>(); await sut.Save <FakeUser>(userId, memento, CancellationToken.None); string blobName = AzureMementoStore.GetMementoBlobName <FakeUser>(userId); ICloudBlob blob = await s_container.GetBlobReferenceFromServerAsync(blobName); blob.Properties.ContentType.Should().Be("application/json"); }
public void GetMementoBlobName_returns_correctly_structured_name() { var userId = Guid.NewGuid(); string s = userId.ToString(); string actual = AzureMementoStore.GetMementoBlobName <FakeUser>(userId); TestContext.WriteLine("{0}", actual); var fragments = new[] { typeof(FakeUser).FullName, s.Substring(0, 2), s.Substring(2, 2), $"{s}.json" }; actual.Should().Be(string.Join("/", fragments)); }
public async Task Save_uploads_memento_blob_correctly() { // Arrange var userId = Guid.NewGuid(); FakeUserMemento memento = fixture.Create <FakeUserMemento>(); // Act await sut.Save <FakeUser>(userId, memento, CancellationToken.None); // Assert CloudBlockBlob blob = s_container.GetBlockBlobReference( AzureMementoStore.GetMementoBlobName <FakeUser>(userId)); blob.Exists().Should().BeTrue(); using (Stream s = await blob.OpenReadAsync()) using (var reader = new StreamReader(s)) { string json = await reader.ReadToEndAsync(); object actual = serializer.Deserialize(json); actual.Should().BeOfType <FakeUserMemento>(); actual.ShouldBeEquivalentTo(memento); } }