public void GetReplicationAction(bool sourceExists, string sourceModified, bool destExists, string destModified, ReplicationFileState expectedState) {
            var source = CreateTestFileInfo(sourceExists, sourceModified);
            var dest = CreateTestFileInfo(destExists, destModified);

            var actualState = this.cabinetReplicator.GetReplicationFileState(source, dest);

            Assert.Equal(expectedState, actualState);
        }
        public async Task ReplicateKey(bool sourceExists, string sourceModified, bool destExists, string destModified, ReplicationFileState expectedState) {
            var source = CreateTestFileInfo(sourceExists, sourceModified);
            var dest = CreateTestFileInfo(destExists, destModified);

            var mockMasterCabinet = new Mock<IFileCabinet>();
            var mockReplicaCabinet = new Mock<IFileCabinet>();
            var mockStream = new Mock<Stream>();
            var mockSaveResult = new Mock<ISaveResult>();

            mockMasterCabinet
                .Setup(m => m.GetItemAsync(ReplicaKey))
                .ReturnsAsync(source);

            mockReplicaCabinet
                .Setup(c => c.GetItemAsync(ReplicaKey))
                .ReturnsAsync(dest);

            mockMasterCabinet
                .Setup(m => m.OpenReadStreamAsync(ReplicaKey))
                .ReturnsAsync(mockStream.Object);

            mockReplicaCabinet
                .Setup(c => c.SaveFileAsync(ReplicaKey, mockStream.Object, HandleExistingMethod.Overwrite, null))
                .ReturnsAsync(mockSaveResult.Object);

            await this.cabinetReplicator.ReplicateKeyAsync(ReplicaKey, mockMasterCabinet.Object, mockReplicaCabinet.Object);

            switch(expectedState) {
                case ReplicationFileState.SourceAdded:
                case ReplicationFileState.SourceNewer:
                    mockMasterCabinet.Verify(c => c.OpenReadStreamAsync(ReplicaKey), Times.Once);
                    mockReplicaCabinet.Verify(c => c.SaveFileAsync(ReplicaKey, mockStream.Object, HandleExistingMethod.Overwrite, null), Times.Once);
                    break;
                case ReplicationFileState.SourceDeleted:
                    mockReplicaCabinet.Verify(c => c.DeleteFileAsync(ReplicaKey), Times.Once);
                    break;
                case ReplicationFileState.ReplicationNewer:
                case ReplicationFileState.Same:
                default:
                    mockMasterCabinet.Verify(c => c.OpenReadStreamAsync(ReplicaKey), Times.Never);
                    mockReplicaCabinet.Verify(c => c.SaveFileAsync(ReplicaKey, mockStream.Object, HandleExistingMethod.Overwrite, null), Times.Never);
                    mockReplicaCabinet.Verify(c => c.DeleteFileAsync(ReplicaKey), Times.Never);
                    break;
            }
        }
        public async Task ReplicateKey(bool sourceExists, string sourceModified, bool destExists, string destModified, ReplicationFileState expectedState)
        {
            var source = CreateTestFileInfo(sourceExists, sourceModified);
            var dest   = CreateTestFileInfo(destExists, destModified);

            var mockMasterCabinet  = new Mock <IFileCabinet>();
            var mockReplicaCabinet = new Mock <IFileCabinet>();
            var mockStream         = new Mock <Stream>();
            var mockSaveResult     = new Mock <ISaveResult>();

            mockMasterCabinet
            .Setup(m => m.GetItemAsync(ReplicaKey))
            .ReturnsAsync(source);

            mockReplicaCabinet
            .Setup(c => c.GetItemAsync(ReplicaKey))
            .ReturnsAsync(dest);

            mockMasterCabinet
            .Setup(m => m.OpenReadStreamAsync(ReplicaKey))
            .ReturnsAsync(mockStream.Object);

            mockReplicaCabinet
            .Setup(c => c.SaveFileAsync(ReplicaKey, mockStream.Object, HandleExistingMethod.Overwrite, null))
            .ReturnsAsync(mockSaveResult.Object);

            await this.cabinetReplicator.ReplicateKeyAsync(ReplicaKey, mockMasterCabinet.Object, mockReplicaCabinet.Object);

            switch (expectedState)
            {
            case ReplicationFileState.SourceAdded:
            case ReplicationFileState.SourceNewer:
                mockMasterCabinet.Verify(c => c.OpenReadStreamAsync(ReplicaKey), Times.Once);
                mockReplicaCabinet.Verify(c => c.SaveFileAsync(ReplicaKey, mockStream.Object, HandleExistingMethod.Overwrite, null), Times.Once);
                break;

            case ReplicationFileState.SourceDeleted:
                mockReplicaCabinet.Verify(c => c.DeleteFileAsync(ReplicaKey), Times.Once);
                break;

            case ReplicationFileState.ReplicationNewer:
            case ReplicationFileState.Same:
            default:
                mockMasterCabinet.Verify(c => c.OpenReadStreamAsync(ReplicaKey), Times.Never);
                mockReplicaCabinet.Verify(c => c.SaveFileAsync(ReplicaKey, mockStream.Object, HandleExistingMethod.Overwrite, null), Times.Never);
                mockReplicaCabinet.Verify(c => c.DeleteFileAsync(ReplicaKey), Times.Never);
                break;
            }
        }
        public void GetReplicationAction(bool sourceExists, string sourceModified, bool destExists, string destModified, ReplicationFileState expectedState)
        {
            var source = CreateTestFileInfo(sourceExists, sourceModified);
            var dest   = CreateTestFileInfo(destExists, destModified);

            var actualState = this.cabinetReplicator.GetReplicationFileState(source, dest);

            Assert.Equal(expectedState, actualState);
        }