public async Task MakePermanent_Returns_NumberEffectedRows()
        {
            // Arrange
            var configRepoMock = new Mock <IConfigRepository>();

            configRepoMock.Setup((m) => m.CommandTimeout).Returns(60);
            var cxn                = new SqlConnectionWrapperMock();
            var repository         = new SqlFilesRepository(cxn.Object, configRepoMock.Object);
            var guid               = Guid.NewGuid();
            var numberEffectedRows = 2;

            cxn.SetupExecuteScalarAsync(
                "[FileStore].MakeFilePermanent",
                new Dictionary <string, object> {
                { "FileId", guid }
            },
                numberEffectedRows);

            // Act
            var rows = await repository.MakeFilePermanent(guid);

            // Assert
            cxn.Verify();
            Assert.AreEqual(numberEffectedRows, rows);
        }
        public async Task DeleteFile_QueryReturnsNull_ReturnsNotNull()
        {
            // Arrange
            var configRepoMock = new Mock <IConfigRepository>();

            configRepoMock.Setup((m) => m.CommandTimeout).Returns(60);
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlFilesRepository(cxn.Object, configRepoMock.Object);
            var guid       = new Guid("34567345673456734567345673456734");

            cxn.SetupExecuteScalarAsync(
                "[FileStore].DeleteFile",
                new Dictionary <string, object> {
                { "FileId", guid }
            },
                1,
                new Dictionary <string, object> {
                { "ExpiredTime", DateTime.UtcNow }
            });

            // Act
            Guid?id = await repository.DeleteFile(guid, DateTime.UtcNow);

            // Assert
            cxn.Verify();
            Assert.IsNotNull(id);
        }
        public async Task GetFile_QueryReturnsEmpty_ReturnsNull()
        {
            // Arrange
            var configRepoMock = new Mock <IConfigRepository>();

            configRepoMock.Setup((m) => m.CommandTimeout).Returns(60);
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlFilesRepository(cxn.Object, configRepoMock.Object);
            var guid       = new Guid("22222222222222222222222222222222");

            File[] result = { };
            cxn.SetupQueryAsync(
                "[FileStore].ReadFileHead",
                new Dictionary <string, object> {
                { "FileId", guid }
            },
                result);

            // Act
            File file = await repository.GetFileHead(guid);

            // Assert
            cxn.Verify();
            Assert.IsNull(file);
        }
        public async Task PostFile_QueryReturnsId_ReturnsId()
        {
            // Arrange
            var configRepoMock = new Mock <IConfigRepository>();

            configRepoMock.Setup((m) => m.CommandTimeout).Returns(60);
            var  cxn        = new SqlConnectionWrapperMock();
            var  repository = new SqlFilesRepository(cxn.Object, configRepoMock.Object);
            File file       = new File {
                FileName = "name", FileType = "type"
            };
            Guid?result = new Guid("12345678901234567890123456789012");

            cxn.SetupExecuteAsync(
                "[FileStore].InsertFileHead",
                new Dictionary <string, object> {
                { "FileName", file.FileName }, { "FileType", file.FileType }, { "FileId", null }
            },
                1,
                new Dictionary <string, object> {
                { "FileId", result }
            });

            // Act
            Guid?id = await repository.PostFileHead(file);

            // Assert
            cxn.Verify();
            Assert.AreEqual(result, id);
        }
        public async Task GetFile_QueryReturnsFile_ReturnsFirst()
        {
            // Arrange
            var configRepoMock = new Mock <IConfigRepository>();

            configRepoMock.Setup((m) => m.CommandTimeout).Returns(60);
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlFilesRepository(cxn.Object, configRepoMock.Object);
            var guid       = new Guid("33333333333333333333333333333333");

            File[] result = { new File {
                                  FileName = "nnnn", FileType = "tttt"
                              } };
            cxn.SetupQueryAsync(
                "[FileStore].ReadFileHead",
                new Dictionary <string, object> {
                { "FileId", guid }
            },
                result);

            // Act
            File file = await repository.GetFileHead(guid);

            // Assert
            cxn.Verify();
            Assert.AreEqual(result.First(), file);
        }