public void AddNewSoftwareThrowExceptionWhenDataIsInvalid() { //Arrange var customerRepository = new Mock <ICustomerRepository>(); var productRepository = new Mock <IProductRepository>(); var orderRepository = new Mock <IOrderRepository>(); Mock <ILogger <SalesAppService> > _mockLogger = new Mock <ILogger <SalesAppService> >(); var salesManagement = new SalesAppService(productRepository.Object, orderRepository.Object, customerRepository.Object, _mockLogger.Object); var dto = new SoftwareDTO() { Title = "The title", Description = "the description", LicenseCode = "license", AmountInStock = 10, UnitPrice = -1//this is a not valid value }; Exception ex = Assert.Throws <ApplicationValidationErrorsException>(() => { //Act var result = salesManagement.AddNewSoftware(dto); } ); Assert.IsType(typeof(ApplicationValidationErrorsException), ex); }
public async Task <IActionResult> PostRequest([FromBody] SoftwareDTO dto) { dto.SessionId = await base.getUserSession(); dto.Requester.Username = CurrentUser; dto.DomainModel.EmployeeEmail = CurrentUserEmail; await _serviceManager.SaveRequestData(dto); return(Ok()); }
public List <RegistrySoftware> ReadRegisteryusingWMI(SoftwareDTO software) { var uninstallregistery32 = ReadUnInstallRegistryusingWMICore(software, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); var uninstallregistery64 = ReadUnInstallRegistryusingWMICore(software, @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"); var registrysoftware32 = ReadRegistrySubkeys(@"SOFTWARE\" + software.AppName, "32"); var registrysoftware64 = ReadRegistrySubkeys(@"SOFTWARE\Wow6432Node\" + software.AppName, "64"); var uniqueList = uninstallregistery32.Concat(uninstallregistery64).Concat(registrysoftware32).Concat(registrysoftware64) .Where(x => x.DisplayName != null) .GroupBy(item => item.DisplayName) .Select(group => group.First()) .ToList(); return(uniqueList); }
public async Task <IActionResult> ProcessRequest([FromBody] SoftwareDTO dto) { if (dto == null) { return(BadRequest()); } if (dto.ManagerDecision == null) { return(BadRequest()); } dto.SessionId = await base.getUserSession(); dto.Requester.Username = CurrentUser; await _serviceManager.ProcessRequest(dto); return(Ok()); }
public void AddNewSoftwareReturnAddedSoftware() { //Arrange var customerRepository = new Mock <ICustomerRepository>(); var orderRepository = new Mock <IOrderRepository>(); var productRepository = new Mock <IProductRepository>(); Mock <MainBCUnitOfWork> _mockContext = new Mock <MainBCUnitOfWork>(); _mockContext.Setup(c => c.Commit()); productRepository.Setup(x => x.Add(It.IsAny <Product>())); productRepository .Setup(x => x.UnitOfWork).Returns(_mockContext.Object); Mock <ILogger <SalesAppService> > _mockLogger = new Mock <ILogger <SalesAppService> >(); var salesManagement = new SalesAppService(productRepository.Object, orderRepository.Object, customerRepository.Object, _mockLogger.Object); var dto = new SoftwareDTO() { Title = "The title", Description = "description", LicenseCode = "license code", AmountInStock = 10, UnitPrice = 10 }; //Act var result = salesManagement.AddNewSoftware(dto); //Assert Assert.NotNull(result); Assert.True(result.Id != Guid.Empty); Assert.Equal(result.Title, dto.Title); Assert.Equal(result.Description, dto.Description); Assert.Equal(result.LicenseCode, dto.LicenseCode); Assert.Equal(result.AmountInStock, dto.AmountInStock); Assert.Equal(result.UnitPrice, dto.UnitPrice); }
public void AddNewSoftwareReturnAddedSoftware() { //Arrange var customerRepository = new SICustomerRepository(); var orderRepository = new SIOrderRepository(); var productRepository = new SIProductRepository(); productRepository.UnitOfWorkGet = () => { var uow = new SIUnitOfWork(); uow.Commit = () => { }; return(uow); }; productRepository.AddProduct = (product) => { }; var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); var dto = new SoftwareDTO() { Title = "The title", Description = "description", LicenseCode = "license code", AmountInStock = 10, UnitPrice = 10 }; //Act var result = salesManagement.AddNewSoftware(dto); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Id != Guid.Empty); Assert.AreEqual(result.Title, dto.Title); Assert.AreEqual(result.Description, dto.Description); Assert.AreEqual(result.LicenseCode, dto.LicenseCode); Assert.AreEqual(result.AmountInStock, dto.AmountInStock); Assert.AreEqual(result.UnitPrice, dto.UnitPrice); }
public void AddNewSoftwareThrowExceptionWhenDataIsInvalid() { //Arrange var customerRepository = new SICustomerRepository(); var productRepository = new SIProductRepository(); var orderRepository = new SIOrderRepository(); var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); var dto = new SoftwareDTO() { Title = "The title", Description = "the description", LicenseCode = "license", AmountInStock = 10, UnitPrice = -1//this is a not valid value }; //Act var result = salesManagement.AddNewSoftware(dto); }
/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/> /// </summary> /// <param name="softwareDTO"><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/></param> public SoftwareDTO AddNewSoftware(SoftwareDTO softwareDTO) { if (softwareDTO == null) { throw new ArgumentException(Messages.warning_CannotAddSoftwareWithNullInformation); } //Create the softare entity var newSoftware = new Software(softwareDTO.Title, softwareDTO.Description, softwareDTO.LicenseCode); //set unit price and stock newSoftware.ChangeUnitPrice(softwareDTO.UnitPrice); newSoftware.IncrementStock(softwareDTO.AmountInStock); //Assign the poid newSoftware.GenerateNewIdentity(); //save software SaveProduct(newSoftware); //return software dto return(newSoftware.ProjectedAs <SoftwareDTO>()); }
public List <ApplicationEvent> GetApplicationEvent(SoftwareDTO software) { List <ApplicationEvent> list = new List <ApplicationEvent>(); ManagementScope scope = new ManagementScope("\\\\.\\root\\CIMV2"); scope.Connect(); SelectQuery query = new SelectQuery("Select * from Win32_NTLogEvent Where EventCode = 11724 "); using (ManagementObjectSearcher ProcessSearcher = new ManagementObjectSearcher(scope, query)) { foreach (ManagementBaseObject log in ProcessSearcher.Get()) { ApplicationEvent item = new ApplicationEvent(); item.Message = log["Message"] == null ? null : log["Message"].ToString(); var param = item.Message.Contains(software.AppName); if (param == false) { continue; } item.ComputerName = log["ComputerName"] == null ? null : log["ComputerName"].ToString(); item.Type = log["Type"] == null ? null : log["Type"].ToString(); item.User = log["User"] == null ? null : log["User"].ToString(); item.EventCode = log["EventCode"] == null ? null : log["EventCode"].ToString(); item.Category = log["Category"] == null ? null : log["Category"].ToString(); item.SourceName = log["SourceName"] == null ? null : log["SourceName"].ToString(); item.RecordNumber = log["RecordNumber"] == null ? null : log["RecordNumber"].ToString(); item.TimeWritten = getDateTimeFromDmtfDate(log["TimeWritten"] == null ? null : log["TimeWritten"].ToString()); list.Add(item); } } return(list); }
public SoftwareDTO Software([FromBody] SoftwareDTO software) { return(_salesAppService.AddNewSoftware(software)); }
private List <RegistrySoftware> ReadUnInstallRegistryusingWMICore(SoftwareDTO software, string softwareRegLoc) { List <RegistrySoftware> programs = new List <RegistrySoftware>(); ManagementScope scope = Connect(); ManagementClass registry = new ManagementClass(scope, new ManagementPath("StdRegProv"), null); ManagementBaseObject inParams = registry.GetMethodParameters("EnumKey"); inParams["hDefKey"] = 0x80000002;//HKEY_LOCAL_MACHINE inParams["sSubKeyName"] = softwareRegLoc; // Read Registry Key Names ManagementBaseObject outParams = registry.InvokeMethod("EnumKey", inParams, null); string[] programGuids = outParams["sNames"] as string[]; if (programGuids == null) { return(programs); } foreach (string subKeyName in programGuids) { var item = new RegistrySoftware(); inParams = registry.GetMethodParameters("GetStringValue"); inParams["sSubKeyName"] = softwareRegLoc + @"\" + subKeyName; inParams["sValueName"] = "DisplayName"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.DisplayName = outParams.Properties["sValue"].Value.ToString(); var param = item.DisplayName.Contains(software.AppName); if (param == false) { continue; } } else { continue; } inParams["sValueName"] = "InstallDate"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.InstallDate = outParams.Properties["sValue"].Value.ToString() == "" ? (DateTime?)null : DateTime.ParseExact(outParams.Properties["sValue"].Value.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture); } inParams["sValueName"] = "Contact"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.Contact = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "DisplayIcon"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.DisplayIcon = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "DisplayVersion"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.DisplayVersion = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "EstimatedSize"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.EstimatedSize = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "HelpLink"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.HelpLink = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "HelpTelephone"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.HelpTelephone = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "InstallLocation"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.InstallLocation = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "InstallSource "; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.InstallSource = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "Language"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.Language = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "ModifyPath_Hidden"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.ModifyPath_Hidden = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "NoModify"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.NoModify = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "NoRemove"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.NoRemove = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "NoRepair"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.NoRepair = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "Publisher"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.Publisher = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "Readme"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.Readme = outParams.Properties["sValue"].Value.ToString(); } inParams["sValueName"] = "UninstallString"; outParams = registry.InvokeMethod("GetStringValue", inParams, null); if (outParams.Properties["sValue"].Value != null) { item.UninstallString = outParams.Properties["sValue"].Value.ToString(); } programs.Add(item); } return(programs); }
public List <Win32_Product> GetProductWithWMI(SoftwareDTO softwares) { List <Win32_Product> products = new List <Win32_Product>(); ManagementScope scope = Connect(); SelectQuery CheckProcess = new SelectQuery("SELECT InstallDate,Name FROM Win32_Product"); using (ManagementObjectSearcher ProcessSearcher = new ManagementObjectSearcher(scope, CheckProcess)) { var WMIproducts = ProcessSearcher.Get(); foreach (ManagementObject mo in WMIproducts) { Win32_Product product = new Win32_Product(); product.Name = mo["Name"] == null ? null : mo["Name"].ToString(); if (product.Name == null) { continue; } var param = product.Name.Contains(softwares.AppName); if (param == false) { continue; } //product.AssignmentType = mo["AssignmentType"].ToString(); //product.Caption = mo["Caption"] == null ? null : mo["Caption"].ToString(); //product.Description = mo["Description"] == null ? null : mo["Description"].ToString(); //product.HelpLink = mo["HelpLink"] == null ? null : mo["HelpLink"].ToString(); //product.HelpTelephone = mo["HelpTelephone"] == null ? null : mo["HelpTelephone"].ToString(); //product.IdentifyingNumber = mo["IdentifyingNumber"] == null ? null : mo["IdentifyingNumber"].ToString(); product.InstallDate = mo["InstallDate"] == null ? (DateTime?)null : DateTime.ParseExact(mo["InstallDate"].ToString(), "yyyyMMdd", CultureInfo.InvariantCulture); //product.InstallDate2 = mo["InstallDate2"] == null ? null : mo["InstallDate2"].ToString(); //product.InstallLocation = mo["InstallLocation"] == null ? null : mo["InstallLocation"].ToString(); //product.InstallSource = mo["InstallSource"] == null ? null : mo["InstallSource"].ToString(); //product.InstallState = mo["InstallState"] == null ? null : mo["InstallState"].ToString(); //product.Language = mo["Language"] == null ? null : mo["Language"].ToString(); //product.LocalPackage = mo["LocalPackage"] == null ? null : mo["LocalPackage"].ToString(); //product.PackageCache = mo["PackageCache"] == null ? null : mo["PackageCache"].ToString(); //product.PackageCode = mo["PackageCode"] == null ? null : mo["PackageCode"].ToString(); //product.PackageName = mo["PackageName"] == null ? null : mo["PackageName"].ToString(); //product.ProductID = mo["ProductID"] == null ? null : mo["ProductID"].ToString(); //product.RegCompany = mo["RegCompany"] == null ? null : mo["RegCompany"].ToString(); //product.RegOwner = mo["RegOwner"] == null ? null : mo["RegOwner"].ToString(); //product.SKUNumber = mo["SKUNumber"] == null ? null : mo["SKUNumber"].ToString(); //product.Transforms = mo["Transforms"] == null ? null : mo["Transforms"].ToString(); //product.URLInfoAbout = mo["URLInfoAbout"] == null ? null : mo["URLInfoAbout"].ToString(); //product.URLUpdateInfo = mo["URLUpdateInfo"] == null ? null : mo["URLUpdateInfo"].ToString(); //product.Vendor = mo["Vendor"] == null ? null : mo["Vendor"].ToString(); //product.Version = mo["Version"] == null ? null : mo["Version"].ToString(); products.Add(product); } } return(products); }
/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IMainBoundedContextService"/> /// </summary> /// <param name="software"><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IMainBoundedContextService"/></param> /// <returns><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IMainBoundedContextService"/></returns> public SoftwareDTO AddNewSoftware(SoftwareDTO software) { return(_salesAppService.AddNewSoftware(software)); }