private void RegisterTestApplication(IFoghornService service) { var notificationTypeDtos = new List <NotificationTypeDto>(); for (var i = 0; i < NumNotificationTypes; i++) { var notificationTypeDto = new NotificationTypeDto { NotificationTypeName = NotificationName + i, NotificationTypeDisplayName = "Test Notfication " + i }; try { var iconFilePath = string.Format(@"..\..\NotificationIcons\{0}{1}.png", NotificationName, i); var iconFile = File.OpenRead(iconFilePath); var iconBuffer = new byte[iconFile.Length]; iconFile.Read(iconBuffer, 0, (int)iconFile.Length); notificationTypeDto.NotificationTypeIcon = iconBuffer; } catch (Exception exception) { Logger.LogException(LogLevel.Error, FailureMessage, exception); throw; } notificationTypeDtos.Add(notificationTypeDto); } var sendingApplicationDto = new SendingApplicationDto { SendingApplicationName = ApplicationTestName }; try { var iconFilePath = string.Format(@"..\..\NotificationIcons\Icon.png"); var iconFile = File.OpenRead(iconFilePath); var iconBuffer = new byte[iconFile.Length]; iconFile.Read(iconBuffer, 0, (int)iconFile.Length); sendingApplicationDto.SendingApplicationIcon = iconBuffer; } catch (Exception exception) { Logger.LogException(LogLevel.Error, FailureMessage, exception); throw; } _testApplicationId = service.RegisterSendingApplication(sendingApplicationDto, notificationTypeDtos); }
public int RegisterSendingApplication(SendingApplicationDto sendingApplicationDto, IEnumerable <NotificationTypeDto> notificationTypeDtos) { var notificationTypes = new List <NotificationType>(); foreach (var notificationTypeDto in notificationTypeDtos) { var notificationType = DataContext.NotificationTypes.FirstOrDefault( x => x.NotificationTypeName == notificationTypeDto.NotificationTypeName); if (notificationType == null) { notificationType = notificationTypeDto.ToEntity(); DataContext.NotificationTypes.Add(notificationType); Logger.Trace("Adding a new NotificationType: {0}, for application: {1}", notificationTypeDto.NotificationTypeName, sendingApplicationDto.SendingApplicationName); } notificationType.NotificationTypeIcon = notificationTypeDto.NotificationTypeIcon; notificationType.NotificationTypeDisplayName = notificationTypeDto.NotificationTypeDisplayName; notificationTypes.Add(notificationType); } var sendingApplication = DataContext.SendingApplications.FirstOrDefault( x => x.SendingApplicationName == sendingApplicationDto.SendingApplicationName); if (sendingApplication == null) { sendingApplication = sendingApplicationDto.ToEntity(); Logger.Trace("Adding a new SendingApplication: {0}", sendingApplicationDto.SendingApplicationName); DataContext.SendingApplications.Add(sendingApplication); } else { sendingApplication.SendingApplicationIcon = sendingApplicationDto.SendingApplicationIcon; } sendingApplication.NotificationTypes.Clear(); foreach (var notificationType in notificationTypes) { sendingApplication.NotificationTypes.Add(notificationType); } DataContext.SaveChanges(); return(sendingApplication.SendingApplicationId); }
public void TestRegisterSendingApplication_LoadNotificationTypesFromExcel_AllLoaded() { var foghornClient = new ChannelFactory <IFoghornService>(new BasicHttpBinding(), new EndpointAddress(ServiceUrl)).CreateChannel(); var notificationTypeDtos = new List <NotificationTypeDto>(); LoadNotificationTypes(notificationTypeDtos); var sendingApplicationDto = new SendingApplicationDto { SendingApplicationName = ApplicationTestName }; LoadApplicationIcon(sendingApplicationDto); foghornClient.RegisterSendingApplication(sendingApplicationDto, notificationTypeDtos); //TODO: Add Assertions }
private static void LoadApplicationIcon(SendingApplicationDto sendingApplicationDto) { Stream iconStream = null; try { iconStream = File.OpenRead(Path.Combine(@"..\..\NotificationIcons", "Icon.png")); var buffer = new byte[iconStream.Length]; iconStream.Read(buffer, 0, (int)iconStream.Length); sendingApplicationDto.SendingApplicationIcon = buffer; } catch (Exception exception) { Logger.LogException(LogLevel.Error, "Exception Ignored", exception); throw; } finally { if (iconStream != null) { iconStream.Close(); } } }