Exemplo n.º 1
0
        public async Task CheckChecksumOnFileItem_the_checksum_does_not_exists_return_fasle()
        {
            //Arrange
            var options      = CreateNewContextOptions();
            var appDbOptions = CreateNewApplicationDbContextOptions();

            FillTheTempDataBase(options);
            AddDataChunksToExistingFileItemToDB(options);
            string TestUserID            = "User-1a-guid-tostring"; // this user exist and has fileitem and datachunks saved.
            string TestDatachunkChecksum = "xxx999checksum";        //fileitems checksum.

            using (var appDbContext = new ApplicationDbContext(appDbOptions))
                using (var context = new CloudDbRepository(options))
                {
                    var service = new CloudMineDbService(context, appDbContext);

                    //Act
                    var result = await service.CheckChecksumOnFileItem(TestUserID, TestDatachunkChecksum);

                    //Assert
                    Assert.Equal(2, context.DataChunks.Count());
                    var viewResult = Assert.IsType <bool>(result);
                    Assert.False(viewResult);
                }
        }
Exemplo n.º 2
0
        public async Task GetAllFilItemAndDataChunks__userId_get_FileItem()
        {
            //Arrange
            var options      = CreateNewContextOptions();
            var appDbOptions = CreateNewApplicationDbContextOptions();

            AddInitFileItemToDb(options);

            AddDataChunksToDB(options);

            string userGuid = "111cf2f2-c675-4e27-ac7a-9f8e43f64334";


            using (var appDbContext = new ApplicationDbContext(appDbOptions))
                using (var context = new CloudDbRepository(options))
                {
                    var service = new CloudMineDbService(context, appDbContext);

                    //Act
                    var result = await service.GetAllFilItemAndDataChunks(userGuid);

                    //Assert
                    Assert.Equal(2, context.DataChunks.Count());
                    var viewResult = Assert.IsType <List <FileItem> >(result);
                    Assert.Equal(2, viewResult.FirstOrDefault().DataChunks.Count());
                }
        }
Exemplo n.º 3
0
        public async Task CheckChecksum_the_checksum_exsists_return_true()
        {
            //Arrange
            var options      = CreateNewContextOptions();
            var appDbOptions = CreateNewApplicationDbContextOptions();

            FillTheTempDataBase(options);
            AddDataChunksToExistingFileItemToDB(options);
            int    FileItemID            = 11;                  // this user exist and has fileitem and datachunks saved.
            string TestDatachunkChecksum = "aa11-checksum-fil"; //aa11-checksum-fil & bb22-checksum-fil exist.

            using (var appDbContext = new ApplicationDbContext(appDbOptions))
                using (var context = new CloudDbRepository(options))
                {
                    var service = new CloudMineDbService(context, appDbContext);

                    //Act
                    var result = await service.CheckChecksum(FileItemID, TestDatachunkChecksum);

                    //Assert
                    Assert.Equal(2, context.DataChunks.Count());
                    var viewResult = Assert.IsType <bool>(result);
                    Assert.True(viewResult);
                }
        }
Exemplo n.º 4
0
        public async Task DeleteByIdUsingAPI_send_int_Id_get_bool_true()
        {
            //Arrange
            var options      = CreateNewContextOptions();
            var appDbOptions = CreateNewApplicationDbContextOptions();

            FillTheTempDataBase(options);
            AddDataChunksToExistingFileItemToDB(options);

            int FileItemId = 11;

            using (var appDbContext = new ApplicationDbContext(appDbOptions))
                using (var context = new CloudDbRepository(options))
                {
                    var service = new CloudMineDbService(context, appDbContext);

                    //Act
                    var result = await service.DeleteByIdUsingAPI(FileItemId);

                    //Assert
                    Assert.Equal(3, context.FileItems.Count());
                    Assert.Equal(0, context.DataChunks.Count());
                    var viewResult = Assert.IsType <bool>(result);
                    Assert.True(result);
                }
        }
Exemplo n.º 5
0
        public async Task GetFiAndDc_send_id_and_userId_get_FileItem()
        {
            //Arrange
            var options      = CreateNewContextOptions();
            var appDbOptions = CreateNewApplicationDbContextOptions();

            FillTheTempDataBase(options);
            AddDataChunksToExistingFileItemToDB(options);
            int    FileItemId = 11;
            string userGuid   = "User-1a-guid-tostring";

            using (var appDbContext = new ApplicationDbContext(appDbOptions))
                using (var context = new CloudDbRepository(options))
                {
                    var service = new CloudMineDbService(context, appDbContext);

                    //Act
                    var result = await service.GetSpecifikFileItemAndDataChunk(FileItemId, userGuid);

                    //Assert
                    Assert.Equal(2, context.DataChunks.Count());
                    Assert.Equal(11, context.DataChunks.FirstOrDefault().FileItemId);
                    Assert.Equal(11, context.DataChunks.FirstOrDefault().Id);
                    var viewResults = Assert.IsType <FileItem>(result);
                    Assert.Equal(2, viewResults.DataChunks.Count());
                }
        }
Exemplo n.º 6
0
        public async Task AddFileUsingAPI_chunk_to_add_is_last__then_change_FiliItem_bool_prop_to_true()
        {
            //Arrange
            var appDbOptions = CreateNewApplicationDbContextOptions();
            var options      = CreateNewContextOptions();

            AddInitFileItemToDb(options);
            var DC = new DataChunk()
            {
                Id = 11, Checksum = "", FileItemId = 1, Data = new byte[10], PartName = "AudioInterface.png.part_1.1"
            };

            using (var appDbContext = new ApplicationDbContext(appDbOptions))
                using (var context = new CloudDbRepository(options))
                {
                    var service = new CloudMineDbService(context, appDbContext);

                    //Act
                    var result = await service.AddFileUsingAPI(DC);

                    //Assert
                    Assert.True(context.FileItems.FirstOrDefault(x => x.Id == 1).IsComplete);
                    var viewResult = Assert.IsType <bool>(result);
                    Assert.True(result);
                }
        }
Exemplo n.º 7
0
        public async Task UpDateByIdUsingAPI_send_int_id_and_FileItem_that_dont_maching_id_return_false()
        {
            //Arrange
            var options      = CreateNewContextOptions();
            var appDbOptions = CreateNewApplicationDbContextOptions();

            FillTheTempDataBase(options);
            var myFileItem = new FileItem()
            {
                Id = 11, IsComplete = false, FileSize = 111, FileName = "EDIT", Description = "edit", DataType = "jpg"
            };
            int FileItemId = 12345;

            using (var appDbContext = new ApplicationDbContext(appDbOptions))
                using (var context = new CloudDbRepository(options))
                {
                    var service = new CloudMineDbService(context, appDbContext);

                    //Act
                    var result = await service.UpDateByIdUsingAPI(FileItemId, myFileItem);

                    //Assert
                    Assert.Equal(4, context.FileItems.Count());
                    var viewResult = Assert.IsType <bool>(result);
                    Assert.False(viewResult);
                    Assert.Equal("name", context.FileItems.FirstOrDefault(x => x.Id == 11).FileName);
                }
        }
Exemplo n.º 8
0
        public async Task AddFileUsingAPI_add_file_and_get_false_catch_save_to_db()
        {
            //Arrange
            var appDbOptions = CreateNewApplicationDbContextOptions();
            var options      = CreateNewContextOptions();

            FillTheTempDataBase(options);
            AddDataChunksToDB(options);

            // Redan existerande DataChunk
            var badDC = new DataChunk()
            {
                Id = 11, FileItemId = 1, Data = new byte[10], PartName = "AudioInterface.png.part_1.2"
            };

            using (var appDbContext = new ApplicationDbContext(appDbOptions))
                using (var context = new CloudDbRepository(options))
                {
                    var service = new CloudMineDbService(context, appDbContext);

                    //Act
                    var result = await service.AddFileUsingAPI(badDC);

                    //Assert
                    var viewResult = Assert.IsType <bool>(result);
                    Assert.False(result);
                }
        }
Exemplo n.º 9
0
        public async Task AddFileUsingAPI_add_file_and_get_true_sucess_save_to_db()
        {
            //Arrange
            var options      = CreateNewContextOptions();
            var appDbOptions = CreateNewApplicationDbContextOptions();

            AddInitFileItemToDb(options);
            Guid myGuid = new Guid("976cf2f2-c675-4e27-ac7a-9f8e43f64334");

            var ds = new DataChunk()
            {
                Id = 0, FileItemId = 1, Data = new byte[10], PartName = "name.png.part_1.1"
            };

            using (var appDbContext = new ApplicationDbContext(appDbOptions))
                using (var context = new CloudDbRepository(options))
                {
                    var service = new CloudMineDbService(context, appDbContext);

                    //Act
                    var result = await service.AddFileUsingAPI(ds);

                    //Assert
                    var viewResult = Assert.IsType <bool>(result);
                    Assert.True(viewResult);
                    Assert.Equal(1, context.DataChunks.FirstOrDefault().FileItemId);
                    Assert.Equal(1, context.FileItems.Count());
                }
        }
Exemplo n.º 10
0
        // Användaren har redan laggt till file (size 2), men överstiger nu gränsen (+99999999). Gränsvärde för  user.StorageSize = 100000000;
        public async Task InitCreateFileItem_second_file_to_big()
        {
            //Arrange
            var options      = CreateNewContextOptions();
            var appDbOptions = CreateNewApplicationDbContextOptions();

            AddUserToDB(appDbOptions);
            FillTheTempDataBase(options);

            var fis = new FileItem()
            {
                UserId = "User-1a-guid-tostring", IsComplete = true, FileSize = 99999999, FileName = "TEST", Description = "test", DataType = "jpg"
            };

            using (var appDbContext = new ApplicationDbContext(appDbOptions))
                using (var context = new CloudDbRepository(options))
                {
                    var service = new CloudMineDbService(context, appDbContext);

                    //Act
                    var result = await service.InitCreateFileItem(fis);

                    //Assert
                    var viewResult = Assert.IsType <bool>(result);
                    Assert.Equal(4, context.FileItems.Count());
                    Assert.False(viewResult);
                }
        }
Exemplo n.º 11
0
        public async Task GetFileByIdUsingAPI_send_int_id_get_FileItem_back()
        {
            //Arrange
            var options      = CreateNewContextOptions();
            var appDbOptions = CreateNewApplicationDbContextOptions();

            FillTheTempDataBase(options);
            int FileItemId = 11;

            using (var appDbContext = new ApplicationDbContext(appDbOptions))
                using (var context = new CloudDbRepository(options))
                {
                    var service = new CloudMineDbService(context, appDbContext);

                    //Act
                    var result = await service.GetFileByIdUsingAPI(FileItemId);

                    //Assert
                    Assert.Equal(4, context.FileItems.Count());
                    var viewResult = Assert.IsType <FileItem>(result);
                    Assert.Equal("User-1a-guid-tostring", viewResult.UserId);
                }
        }
Exemplo n.º 12
0
        public async Task DoesAllChunksExist_count_datachunks_count_and_actual_count_is__Not_same_return_false()
        {
            //Arrange
            var options      = CreateNewContextOptions();
            var appDbOptions = CreateNewApplicationDbContextOptions();

            FillTheTempDataBase(options);
            AddCorruptDataChunksToExistingFileItemToDB(options); // partname säger att det ska finnas 3 parts, fast det finns bara 2.
            int fileItemID = 11;

            using (var appDbContext = new ApplicationDbContext(appDbOptions))
                using (var context = new CloudDbRepository(options))
                {
                    var service = new CloudMineDbService(context, appDbContext);

                    //Act
                    var result = await service.DoesAllChunksExist(fileItemID);

                    //Assert
                    Assert.Equal(2, context.DataChunks.Count());
                    var viewResult = Assert.IsType <bool>(result);
                    Assert.False(viewResult);
                }
        }
Exemplo n.º 13
0
        public async Task GetAllFilesUsingAPI_get_all_the_users_files_get_a_FileItemSet()
        {
            //Arrange
            var options      = CreateNewContextOptions();
            var appDbOptions = CreateNewApplicationDbContextOptions();

            FillTheTempDataBase(options);
            string userGuid = "User-1a-guid-tostring";

            using (var appDbContext = new ApplicationDbContext(appDbOptions))
                using (var context = new CloudDbRepository(options))
                {
                    var service = new CloudMineDbService(context, appDbContext);

                    //Act
                    var result = await service.GetAllFilesUsingAPI(userGuid);

                    //Assert
                    Assert.Equal(4, context.FileItems.Count());
                    var viewResult = Assert.IsType <FileItemSet>(result);
                    Assert.Equal(1, viewResult.ListFileItems.Count());
                    Assert.Equal(11, viewResult.ListFileItems.FirstOrDefault().Id);
                }
        }