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); } }
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); } }
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()); } }
// 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); } }
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); } }
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); } }
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()); } }
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()); } }
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); } }
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); } }
private void AddInitFileItemToDb(DbContextOptions <CloudDbRepository> options) { using (var context = new CloudDbRepository(options)) { Guid FileItemGuid = new Guid("976cf2f2-c675-4e27-ac7a-9f8e43f64334"); string userGuid = "111cf2f2-c675-4e27-ac7a-9f8e43f64334"; context.FileItems.Add(new FileItem { Id = 1, UserId = userGuid, DataChunks = null, IsComplete = false, FileSize = 111, FileName = "TEST", Description = "test", DataType = "jpg" }); context.SaveChanges(); } }
private void AddDataChunksToDB(DbContextOptions <CloudDbRepository> options) { using (var context = new CloudDbRepository(options)) { context.DataChunks.Add(new DataChunk { Id = 11, FileItemId = 1, Checksum = "aa11-checksum-fil", Data = new byte[10], PartName = "name.png.part_1.2" }); context.DataChunks.Add(new DataChunk { Id = 22, FileItemId = 1, Checksum = "bb122-checksum-fil", Data = new byte[01], PartName = "name.png.part_2.2" }); context.SaveChanges(); } }
private void FillTheTempDataBase(DbContextOptions <CloudDbRepository> options) { using (var context = new CloudDbRepository(options)) { context.FileItems.Add(new Models.FileItem { Id = 11, UserId = "User-1a-guid-tostring", Checksum = "aaa111checksum", DataType = "typ", FileName = "name", IsComplete = true, Description = "about", FileSize = 2, Uploaded = new DateTime(2016, 12, 02) }); context.FileItems.Add(new Models.FileItem { Id = 22, UserId = "User-2a-guid-tostring", Checksum = "bbb222checksum", DataType = "typ", FileName = "name", IsComplete = true, Description = "about", FileSize = 1, Uploaded = new DateTime(2016, 12, 02) }); context.FileItems.Add(new Models.FileItem { Id = 33, UserId = "User-3a-guid-tostring", Checksum = "ccc333checksum", DataType = "typ", FileName = "name", IsComplete = true, Description = "about", FileSize = 1, Uploaded = new DateTime(2016, 12, 02) }); context.FileItems.Add(new Models.FileItem { Id = 44, UserId = "User-4a-guid-tostring", Checksum = "ddd444checksum", DataType = "typ", FileName = "name", IsComplete = true, Description = "about", FileSize = 1, Uploaded = new DateTime(2016, 12, 02) }); context.SaveChanges(); } }
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); } }
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); } }
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); } }
public CloudMineDbService(CloudDbRepository context, ApplicationDbContext appDbContext) { _context = context; _appDbContext = appDbContext; }