public async Task CreateAndUploadAttachment() { var tempStream = new MemoryStream(); var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var mock = new Mock<ITimelineService>(); mock.Setup(m => m.PutJsonAsync(It.IsAny<string>(), It.IsAny<object>())).Returns(TestUtils.GetCompletedTask(AttachmentJson)); mock.Setup(m => m.FileOpenWrite(It.IsAny<string>())).Returns(tempStream); mock.Setup(m => m.FileExists(It.IsAny<string>())).Returns(true); var uploadStream = new MemoryStream(data); await Attachment.CreateAndUploadAsync(mock.Object, "ID1", "test.txt", uploadStream); Assert.AreEqual(tempStream.Length, uploadStream.Length); mock.Verify(m => m.PutJsonAsync("TimelineEventAttachment/Create", It.IsAny<object>())); mock.Verify(m => m.UploadFileAsync(It.IsAny<string>(), It.IsAny<string>())); mock.Verify(m => m.FileDelete(It.IsAny<string>())); }