//Test case for hardware added public void Add_Hardware_ReturnsTrue() { var hardware = new Hardware() { id = 1, name = "laptop", brand = "hp", model = "hp231", price = 10000 }; var service = new AssetService <Hardware>(new MockRepository <Hardware>()); var expected = service.Add(hardware); Assert.True(expected == true); }
//Test case for checking added book public void Add_Book_ReturnsTrue() { var book = new Book() { name = "Python", author = "Guido", edition = "1st", price = 1000 }; var service = new AssetService <Book>(new MockRepository <Book>()); var expected = service.Add(book); Assert.True(expected == true); }
//Test case for software added public void Add_Software_ReturnsTrue() { var software = new Software() { name = "Antivirus", provider = "Avast", version = "av1", price = 1500 }; var service = new AssetService <Software>(new MockRepository <Software>()); var expected = service.Add(software); Assert.True(expected == true); }
public void GetHardwareById_ReturnsHardware() { var hardware = new Hardware() { name = "Monitor", model = "intel23", brand = "intel", price = 10000 }; var service = new AssetService <Hardware>(new MockRepository <Hardware>()); service.Add(hardware); var id = 1; var expected = service.GetAsset(id); Assert.False(expected == null); }
public void GetSoftwareById_ReturnsSoftware() { var software = new Software() { name = "Antivirus", provider = "Avast", version = "av1", price = 1500 }; var service = new AssetService <Software>(new MockRepository <Software>()); service.Add(software); var id = 1; var expected = service.GetAsset(id); Assert.False(expected == null); }
public void Get_AllBooks_ReturnsBookList() { var book1 = new Book() { name = "Java", author = "Guido", edition = "1st", price = 1000 }; var book2 = new Book() { name = "Java", author = "Guido", edition = "1st", price = 1000 }; var book3 = new Book() { name = "Java", author = "Guido", edition = "1st", price = 1000 }; var service = new AssetService <Book>(new MockRepository <Book>()); service.Add(book1); service.Add(book2); service.Add(book3); var expected = service.GetAllAssets(); Assert.Equal(3, expected.Count); }
public void GetBookById_ReturnsBook() { var book = new Book() { name = "Java", author = "Guido", edition = "1st", price = 1000 }; var service = new AssetService <Book>(new MockRepository <Book>()); service.Add(book); var id = 1; var expected = service.GetAsset(id); Assert.False(expected == null); }
public void Delete_Book_ReturnsTrue() { var book = new Book() { id = 1, name = "Java", author = "Guido", edition = "1st", price = 1000 }; var service = new AssetService <Book>(new MockRepository <Book>()); service.Add(book); var expected = service.Delete(book.id); Assert.False(expected == null); }
public void Get_AllHardwares_ReturnsHardwareList() { var hardware1 = new Hardware() { name = "laptop", model = "hp12", brand = "hp", price = 120000 }; var hardware2 = new Hardware() { name = "laptop", model = "hp123", brand = "hp", price = 100000 }; var hardware3 = new Hardware() { name = "monitor", model = "hp1234", brand = "hp", price = 30000 }; var service = new AssetService <Hardware>(new MockRepository <Hardware>()); service.Add(hardware1); service.Add(hardware2); service.Add(hardware3); var expected = service.GetAllAssets(); Assert.Equal(3, expected.Count); }
public void Get_AllSoftwares_ReturnsSoftwareList() { var software1 = new Software() { name = "Antivirus", provider = "Avast", version = "1st", price = 1200 }; var software2 = new Software() { name = "Wordpad", provider = "MS Office", version = "3rd", price = 1000 }; var software3 = new Software() { name = "Antivirus", provider = "Avast", version = "2nd", price = 3000 }; var service = new AssetService <Software>(new MockRepository <Software>()); service.Add(software1); service.Add(software2); service.Add(software3); var expected = service.GetAllAssets(); Assert.Equal(3, expected.Count); }
public void Delete_Software_ReturnsTrue() { var software = new Software() { id = 1, name = "Antivirus", provider = "Avast", version = "av1", price = 1500 }; var service = new AssetService <Software>(new MockRepository <Software>()); service.Add(software); var expected = service.Delete(software.id); Assert.False(expected == null); }
public void Update_Hardware_ReturnsTrue() { var hardware = new Hardware() { id = 1, name = "laptop", brand = "hp", model = "hp231", price = 10000 }; var service = new AssetService <Hardware>(new MockRepository <Hardware>()); service.Add(hardware); var hardwareChanges = service.GetAsset(hardware.id); hardwareChanges.price = 2000; var expected = service.Update(hardwareChanges); Assert.False(expected == null); }
private static void AddDataForTesting(DataContext context) { #region Model var modelMinRequiredRecord = 1; var modelId = 0; var modelService = new ModelService(context); if (context.Models.LongCount() <= modelMinRequiredRecord) { for (var i = 0; i <= modelMinRequiredRecord; i++) { var obj = new Model { Name = string.Format("Model {0}", (i + 1)) }; modelService.Add(obj); if (modelId == 0) { modelId = obj.Id; } } } #endregion #region Category var categoryMinRequiredRecord = 1; if (context.Categories.LongCount() <= categoryMinRequiredRecord) { var categoryService = new CategoryService(context); for (var i = 0; i <= categoryMinRequiredRecord; i++) { var obj = new Category { Name = string.Format("Category {0}", (i + 1)) }; categoryService.Add(obj); } } #endregion #region Manufacturer var manufacturerMinRequiredRecord = 1; if (context.Manufacturers.LongCount() <= manufacturerMinRequiredRecord) { var manufacturerService = new ManufacturerService(context); for (var i = 0; i <= manufacturerMinRequiredRecord; i++) { var obj = new Manufacturer { Name = string.Format("Manufacturer {0}", (i + 1)) }; manufacturerService.Add(obj); } } #endregion #region Processor var processorMinRequiredRecord = 1; if (context.Processors.LongCount() <= processorMinRequiredRecord) { var processorService = new ProcessorService(context); for (var i = 0; i <= processorMinRequiredRecord; i++) { var obj = new Processor { Name = string.Format("Processor {0}", (i + 1)) }; processorService.Add(obj); } } #endregion #region Size var hardDiskMinRequiredRecord = 1; if (context.HardDiskSizes.LongCount() <= hardDiskMinRequiredRecord) { var hdService = new HardDiskSizeService(context); for (var i = 0; i <= hardDiskMinRequiredRecord; i++) { var obj = new HardDisk { Size = string.Format("{0}", (i + 1)) }; hdService.Add(obj); } } var memoryMinRequiredRecord = 1; if (context.MemorySizes.LongCount() <= memoryMinRequiredRecord) { var ramService = new MemorySizeService(context); for (var i = 0; i <= memoryMinRequiredRecord; i++) { var obj = new Memory { Size = string.Format("{0}", (i + 1)) }; ramService.Add(obj); } } var videoCardMinRequiredRecord = 1; if (context.VideoCardSizes.LongCount() <= videoCardMinRequiredRecord) { var vcService = new VideoCardSizeService(context); for (var i = 0; i <= videoCardMinRequiredRecord; i++) { var obj = new VideoCard { Size = string.Format("{0}", (i + 1)) }; vcService.Add(obj); } } #endregion #region Supplier var supplierMinRequiredRecord = 1; if (context.Suppliers.LongCount() <= supplierMinRequiredRecord) { var supplierService = new SupplierService(context); for (int i = 0; i <= supplierMinRequiredRecord; i++) { var obj = new Supplier { Name = "Supplier " + i }; supplierService.Add(obj); } } #endregion #region User var userMinRequiredRecord = 1; if (context.Users.LongCount() <= userMinRequiredRecord) { var userService = new UserService(context); for (var i = 0; i <= userMinRequiredRecord; i++) { var obj = new User { FullName = "User " + (i + 1), UserName = "******" + (i + 1), }; userService.Add(obj, "blotocol"); } } #endregion #region Asset var assetMinRequiredRecord = 1; if (context.Assets.LongCount() <= assetMinRequiredRecord) { var service = new AssetService(context); for (int i = 0; i <= assetMinRequiredRecord; i++) { var obj = new Asset { AssetTag = "Asset Tag" + i, Name = "Asset Name" + i, Status = StatusType.Available, ModelId = modelId }; service.Add(obj); } } #endregion }
public static Task <AssetModel> GetAsset(BundleConfig.BundleTypes type, string assetGuid, string name = null, IProgress <Tuple <string, float> > progressCallback = null) { Init(); var assetService = new AssetService(); var found = assetService.Get(assetGuid); if (found != null) { if (File.Exists(found.LocalPath)) { return(Task.FromResult(found)); } else { Debug.Log($"removing stale entry from assetService due to missing file: {found.LocalPath}"); assetService.Delete(assetGuid); } } var typeString = BundleConfig.singularOf(type); if (name == null) { name = typeString; } string localPath = WebUtilities.GenerateLocalPath(assetGuid, type); Uri uri = new Uri(Config.CloudUrl + "/api/v1/assets/download/bundle/" + assetGuid); var progressState = new Tuple <string, float>(name, 0.0f); progressCallback?.Report(new Tuple <string, float>(name, 0.0f)); Debug.Log($"{name} Download at 0%"); var t = new TaskCompletionSource <AssetModel>(); downloads.Enqueue(new Download(uri, localPath, progress => { progressCallback?.Report(new Tuple <string, float>(name, progress)); Debug.Log($"{name} Download at {progress}%"); }, (success, ex) => { if (success) { try { var model = new AssetModel() { AssetGuid = assetGuid, Type = typeString, Name = name, LocalPath = localPath, DateAdded = DateTime.UtcNow.ToString() }; assetService.Add(model); Debug.Log($"{name} Download Complete."); progressCallback?.Report(new Tuple <string, float>(name, 100)); t.TrySetResult(model); } catch (Exception e) { t.TrySetException(e); } } else { t.TrySetException(ex); } })); return(t.Task); }