public void getApplicationsTest() { Repository target = new Repository(); List<Entities.aspnet_Applications> apps = target.GetApplications(); Assert.IsNotNull(apps, "got nothing back"); Assert.AreEqual(1, apps.Count, "Expected 1 application to be returned"); }
public void NewProgramSesion() { newSesion.CreationTime = DateTime.Now; newSesion.userIP = ip; IRepository repository = new Repository(SessionFactoryProvider); repository.Save(newSesion); repository.Commit(); foreach (string url in urls) { if(url != "") if (IsValidUrl(url)) { Uri uri = new Uri(url, UriKind.RelativeOrAbsolute); ProgramManager pm = new ProgramManager(uri, newSesion); pm.Execute(amount, time, buffer); } else return; } buffer.Write(); var t = DateTime.Now - newSesion.CreationTime; var q = (from sesion in repository.AsQueryable<Sesions>() where sesion == newSesion select sesion).Single(); q.ExecutionTime = t.Value.Seconds + t.Value.Minutes * 60 + t.Value.Hours * 3600; repository.Save(q); repository.Commit(); if (onSesionEnd != null) onSesionEnd(q.ExecutionTime.ToString()); //Thread.Sleep(3000); //ISesionToXML s2x = new SesionToXML(); //s2x.ConvertSesionToXML(newSesion, "C:/hugas.xml"); }
public static void Run(Repository repo, string validEmailAddressesFilename, string invalidEmailAddressesFilename) { List<string> invalidemailAddresses; var validEmailAddresses = Extractor.GetEmailAddresses(repo.StorageWrapper.Data.MineableDataDirectory, out invalidemailAddresses, null); var directory = repo.StorageWrapper.Data.MineableDataResultsDirectory; var fullPath = directory + validEmailAddressesFilename; Console.WriteLine("Saving..."); DirectoryCreator.EnsureExistance(directory + validEmailAddressesFilename); DirectoryCreator.EnsureExistance(directory + invalidEmailAddressesFilename); File.WriteAllLines(directory + validEmailAddressesFilename, validEmailAddresses); File.WriteAllLines(directory + invalidEmailAddressesFilename, invalidemailAddresses); Console.WriteLine("A total of {0} email addresses saved to - {1}\n", validEmailAddresses.Count, fullPath); if (UIRetriever.GetBool(string.Format("View {0}?", validEmailAddressesFilename))) { FileVisualiser.Show(fullPath); } if (UIRetriever.GetBool(string.Format("View {0}?", directory))) { DirectoryVisualiser.ShowFile(fullPath); } }
public void RepositoryGetFromMultipleItems_ShouldReturnCorrectResult() { // Arrange IRepository<User> repository = new Repository<User>(); User user1 = new User("test user1", "password", Roles.User); User user2 = new User("test user2", "password", Roles.User); User user3 = new User("test user3", "password", Roles.User); User user4 = new User("test user4", "password", Roles.User); User user5 = new User("test user5", "password", Roles.User); User user6 = new User("test user6", "password", Roles.User); User user7 = new User("test user7", "password", Roles.User); repository.Add(user1); repository.Add(user2); repository.Add(user3); repository.Add(user4); repository.Add(user5); repository.Add(user6); repository.Add(user7); // Act User foundUser = repository.Get(7); // Assert Assert.AreEqual(user7, foundUser); }
private static void CreateUrl() { IRepository repository = new Repository(SessionFactoryProvider); var q = (from code in repository.AsQueryable<ResponseCodes>() where code.ResponseCode == 501 select code).Single(); using (var transaction = new TransactionScope()){ var ses = new Sesions { ExecutionTime = 4525, CreationTime = DateTime.Now, userIP = "asad" }; repository.Save(ses); var url = new URLs { url = new Uri("http://www.google.lt"), sesion = ses, }; repository.Save(url); var response = new Responses { ResponseTime = 12345, URL = url, ResponseCode = q, RequestStartTime = DateTime.Now }; repository.Save(response); repository.Commit(); transaction.Complete(); } Sesions q2 = (from ses in repository.AsQueryable<Sesions>() where ses.userIP == "asad" select ses).Single(); //ISesionToXML s2x = new SesionToXML(); //s2x.ConvertSesionToXML(q2, "C:/hugas.xml"); }
public static void AddClient(Repository repo) { var client = new ClientEntity { PointOfContactName = UIRetriever.GetString(Nameof<ClientEntity>.Property(e => e.PointOfContactName)), PointOfContactEmail = UIRetriever.GetString(Nameof<ClientEntity>.Property(e => e.PointOfContactEmail)), CompanyInformationEntity = new CompanyInformationEntity { Name = UIRetriever.GetString(Nameof<CompanyInformationEntity>.Property(e => e.Name)), Slogan = UIRetriever.GetString(Nameof<CompanyInformationEntity>.Property(e => e.Slogan), true), AddressLine1 = UIRetriever.GetString(Nameof<CompanyInformationEntity>.Property(e => e.AddressLine1)), AddressLine2 = UIRetriever.GetString(Nameof<CompanyInformationEntity>.Property(e => e.AddressLine2), true), Locality = UIRetriever.GetString(Nameof<CompanyInformationEntity>.Property(e => e.Locality)), PostalTown = UIRetriever.GetString(Nameof<CompanyInformationEntity>.Property(e => e.PostalTown)), PostCode = UIRetriever.GetString(Nameof<CompanyInformationEntity>.Property(e => e.PostCode)), Country = UIRetriever.GetString(Nameof<CompanyInformationEntity>.Property(e => e.Country), true), WebsiteUrl = UIRetriever.GetString(Nameof<CompanyInformationEntity>.Property(e => e.WebsiteUrl), true), CellPhone = UIRetriever.GetString(Nameof<CompanyInformationEntity>.Property(e => e.CellPhone), true), OfficePhone = UIRetriever.GetString(Nameof<CompanyInformationEntity>.Property(e => e.OfficePhone), true) } }; repo.ClientsWrapper.Data.Add(client); repo.ClientsWrapper.Save(); Console.WriteLine("\nNew client \"{0}\" added.\n", client.PointOfContactName); }
public void ConvertSesionToXML(Sesions sesion, StringWriter stream) { IRepository repository = new Repository(SessionFactoryProvider); XmlWriterSettings setings = new XmlWriterSettings(); setings.Indent = true; setings.IndentChars = " "; using (XmlWriter writer = XmlWriter.Create(stream, setings)) { writer.WriteStartDocument(); writer.WriteStartElement("Sesion"); writer.WriteElementString("StatupTime", sesion.CreationTime.ToString()); writer.WriteStartElement("URLs"); List<URLs> q1 = (from url in repository.AsQueryable<URLs>() where url.sesion == sesion select url).ToList<URLs>(); foreach (URLs url in q1) { writer.WriteStartElement("URL"); writer.WriteElementString("url", url.url.ToString()); writer.WriteStartElement("Responses"); List<Responses> q2 = (from response in repository.AsQueryable<Responses>() where response.URL == url select response).ToList<Responses>(); foreach (Responses response in q2) { writer.WriteStartElement("Response"); var q3 = (from code in repository.AsQueryable<ResponseCodes>() where code == response.ResponseCode select code.ResponseCode).Single(); writer.WriteElementString("ResponseCode", q3.ToString()); writer.WriteElementString("RequestTime", response.RequestStartTime.ToLongTimeString() + ":" + response.RequestStartTime.Millisecond); writer.WriteElementString("ResponseTime", response.ResponseTime.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); } }
public string StreamFromSesionTime(DateTime time) { IRepository repository = new Repository(SessionFactoryProvider); var q = (from sesion in repository.AsQueryable<Sesions>() where sesion.CreationTime == time select sesion).Single(); ISesionToXML stx = new SesionToXML(); stx.ConvertSesionToXML(q, stream); return stream.ToString(); }
public void RepositoryGet_NotExistentId_ShoudReturnNull() { var repository = new Repository<IDbEntity>(); repository.Add(new User("usernammee", "Password", Roles.User)); Assert.IsNull(repository.Get(4)); }
public void CheckCanGetFromEmailAddress() { List<string> bad; var repo = new Repository(); var list = Extractor.GetEmailAddresses(repo.StorageWrapper.Data.MineableDataDirectory, out bad, 50); Assert.IsTrue(!list.Any(x => x.Contains(";"))); }
public IList<Sesions> selectByIp(string ip) { IRepository repository = new Repository(SessionFactoryProvider); var list = (from sesion in repository.AsQueryable<Sesions>() where sesion.userIP == ip select sesion).ToList<Sesions>(); return list; }
public static void MergeFiles(Repository repo) { var f1 = repo.StorageWrapper.Data.MineableDataResultsDirectory + Extractor.UniqueEmailAddressesFilename; var f2 = repo.StorageWrapper.Data.MineableDataDirectory + Extractor.LinkedInFilename; var f3 = repo.StorageWrapper.Data.MineableDataDirectory + Extractor.IgnoreListFilename; if (!File.Exists(f1)) { Console.WriteLine("Unable to locate " + f1); return; } if (!File.Exists(f2)) { Console.WriteLine("Unable to locate " + f2); return; } if (!File.Exists(f3)) { Console.WriteLine("Unable to locate " + f3); return; } var mozilla = File.ReadLines(f1).ToList(); var linkedIn = File.ReadLines(f2).ToList(); var ignore = File.ReadLines(f3).ToList(); var final = new List<string>(); foreach (var line in mozilla.Where(line => !final.Contains(line.ToLower())).Where(line => ignore.All(ignorePart => !line.ToLower().Contains(ignorePart.ToLower())))) { final.Add(line.ToLower()); } foreach (var line in linkedIn.Where(line => !final.Contains(line.ToLower())).Where(line => ignore.All(ignorePart => !line.ToLower().Contains(ignorePart.ToLower())))) { final.Add(line.ToLower()); } final.Sort(); File.WriteAllLines(repo.StorageWrapper.Data.MineableDataResultsDirectory + Extractor.ConvergedEmailAddressesFilename, final); var domains = final.Where(x => x.Contains('@')).Select(x => x.Split('@')[1]).Distinct().ToList(); domains.Sort(); File.WriteAllLines(repo.StorageWrapper.Data.MineableDataResultsDirectory + Extractor.UniqueDomainsFilename, domains); if (UIRetriever.GetBool(String.Format("View {0}?", Extractor.ConvergedEmailAddressesFilename))) { FileVisualiser.Show(repo.StorageWrapper.Data.MineableDataResultsDirectory + Extractor.ConvergedEmailAddressesFilename); } if (UIRetriever.GetBool(String.Format("View {0}?", repo.StorageWrapper.Data.MineableDataResultsDirectory))) { DirectoryVisualiser.ShowFile(repo.StorageWrapper.Data.MineableDataResultsDirectory + Extractor.ConvergedEmailAddressesFilename); } }
public void RepositoryGet_ShoudReturnItemById() { var repository = new Repository<IDbEntity>(); repository.Add(new User("usernammee", "Password", Roles.User)); repository.Add(new User("usernamme1e", "Passwo2rd", Roles.User)); Assert.AreEqual(1, repository.Get(1).Id); Assert.AreEqual(2, repository.Get(2).Id); }
public ProgramManager(Uri uri, Sesions sesion) { responsesGotten = 0; url = new URLs(); url.sesion = sesion; url.url = uri; IRepository repository = new Repository(SessionFactoryProvider); repository.Save(url); repository.Commit(); }
public void RepositoryGetFromEmpty_ShouldReturnNull() { // Arrange IRepository<User> repository = new Repository<User>(); // Act User foundUser = repository.Get(1); // Assert Assert.AreEqual(null, foundUser); }
public static void SetStorageDirectories(Repository repo) { var invoiceDirectory = GetInvoiceDirectory(Nameof<StorageEntity>.Property(e => e.InvoiceDirectory)); var emailExportDirectory = GetInvoiceDirectory(Nameof<StorageEntity>.Property(e => e.MineableDataDirectory)); var emailDataMiningResultsDirectory = GetInvoiceDirectory(Nameof<StorageEntity>.Property(e => e.MineableDataResultsDirectory)); repo.StorageWrapper.Data.InvoiceDirectory = invoiceDirectory; repo.StorageWrapper.Data.MineableDataDirectory = emailExportDirectory; repo.StorageWrapper.Data.MineableDataResultsDirectory = emailDataMiningResultsDirectory; repo.StorageWrapper.Save(); }
public void GetMessage_MessageNotSet_ReturnsNull() { //Arrange var loggerMock = new Mock<ILogger>(); IRepository repository = new Repository(loggerMock.Object); //Act var messageReceived = repository.GetMessage(); //Assert Assert.IsTrue(string.IsNullOrEmpty(messageReceived)); }
public void Clear_LoggerCalledCorrecty_CalledWithCorrectMessage() { //Arrange const string messageSent = "Called from clear"; var loggerMock = new Mock<ILogger>(); IRepository repository = new Repository(loggerMock.Object); //Act repository.Clear(); //Assert loggerMock.Verify(logger => logger.Log(messageSent)); }
public IList<URLs> selectUrlsBySesionTime(DateTime date, string ip) { IRepository repository = new Repository(SessionFactoryProvider); var curentSesion = (from sesion in repository.AsQueryable<Sesions>() where sesion.CreationTime == date && sesion.userIP == ip select sesion).Single(); var list = (from url in repository.AsQueryable<URLs>() where url.sesion == curentSesion select url).ToList<URLs>(); return list; }
/// <summary> /// Initializes a new instance of the <see cref="VisitorOrderProcessor" /> class. /// </summary> /// <param name="innerProcessor">The inner processor.</param> /// <param name="processingStrategy">The processing strategy.</param> /// <param name="repository">The repository.</param> /// <param name="orderSecurity">The order security.</param> public VisitorOrderProcessor(OrderProcessor innerProcessor, ProcessingStrategy processingStrategy, Repository<Order> repository, VisitorOrderSecurity orderSecurity) { Assert.IsNotNull(innerProcessor, "Unable to cancel the order. Inner Order Processor cannot be null."); Assert.IsNotNull(processingStrategy, "Unable to cancel the order. Order Processing Strategy cannot be null."); Assert.IsNotNull(repository, "Unable to cancel the order. Order Repository cannot be null."); Assert.IsNotNull(orderSecurity, Texts.UnableToSaveTheOrdersOrderSecurityCannotBeNull); this.innerProcessor = innerProcessor; this.processingStrategy = processingStrategy; this.repository = repository; this.orderSecurity = orderSecurity; }
public static void EmailIfRequested(Repository repository, string pdfFilename, IInvoiceDetails invoiceDetails, DateTime now) { var send = UIRetriever.GetBool("Do you want to email this invoice to a client?"); if (send) { var emailTarget = ClientSelector.Get(repository.ClientsWrapper.Data); SendEmailWithAttachement(emailTarget, repository.EmailWrapper.Data, invoiceDetails, pdfFilename, now); EmailSentNotifier.ShowSentToClient(emailTarget); } Console.WriteLine(""); }
public void RepositoryGetInvalidIndex_ShouldReturnNull() { // Arrange IRepository<User> repository = new Repository<User>(); User user = new User("test user", "password", Roles.User); repository.Add(user); // Act User foundUser = repository.Get(13); // Assert Assert.AreEqual(null, foundUser); }
public void RepositoryGetFromOneItem_ShouldReturnCorrectResult() { // Arrange IRepository<User> repository = new Repository<User>(); User user = new User("test user", "password", Roles.User); repository.Add(user); // Act User foundUser = repository.Get(1); // Assert Assert.AreEqual(user, foundUser); }
private static void Main(string[] args) { var repo = new Repository(); if (args.ToList().Contains("-weekly")) { InvoiceCreationUi.RunAutomatedWeeklyInvoice(repo); } else { RunInteractive(repo); } }
public void Clear_MessageSet_SetCorrectly() { //Arrange const string messageSent = "Called from clear"; var loggerMock = new Mock<ILogger>(); IRepository repository = new Repository(loggerMock.Object); //Act repository.Clear(); //Assert Assert.AreEqual(messageSent, repository.GetMessage()); }
public void Load_LoggerCalledCorrecty_CalledOnce() { //Arrange const string messageSent = "Called from load"; var loggerMock = new Mock<ILogger>(); IRepository repository = new Repository(loggerMock.Object); //Act repository.Load(); //Assert loggerMock.Verify(logger => logger.Log(messageSent), Times.Exactly(1)); }
public static void ResourceHandOut() { var logicProvider = new LogicProvider(); var users = new Repository<ApplicationUser>(new GalaxyStormDbContext()); var pOs = users.All().Select(x => x.PlayerObject).ToList(); foreach (var pO in pOs) { var levelE = pO.Buildings.SolarCollectorLevel; var levelC = pO.Buildings.CrystalExtractorLevel; var levelM = pO.Buildings.MetalScrapperLevel; var modifier = logicProvider.Technologies.MoreResources.Modifier[pO.Technologies.MoreResourcesLevel]; var energyGeneration = (logicProvider.Buildings.SolarCollector.ResourceGeneration[levelE] * pO.Planet.EnergyModifier) / 60; var crystalGeneration = (logicProvider.Buildings.CrystalExtractor.ResourceGeneration[levelC] * pO.Planet.CrystalModifier) / 60; var metalGeneration = (logicProvider.Buildings.MetalScrapper.ResourceGeneration[levelM] * pO.Planet.MetalModifier) / 60; if (energyGeneration > (long) energyGeneration) { pO.Resources.Energy += (long)(energyGeneration + 1) + (long)((energyGeneration + 1) * modifier); } else { pO.Resources.Energy += (long)energyGeneration + (long)(energyGeneration * modifier); } if (crystalGeneration > (long)crystalGeneration) { pO.Resources.Crystal += (long)(crystalGeneration + 1) + (long)((crystalGeneration + 1) * modifier); } else { pO.Resources.Crystal += (long)crystalGeneration + (long)(crystalGeneration * modifier); } if (metalGeneration > (long)metalGeneration) { pO.Resources.Metal += (long)(metalGeneration + 1) + (long)((metalGeneration + 1) * modifier); } else { pO.Resources.Metal += (long)metalGeneration + (long)(metalGeneration * modifier); } } users.SaveChanges(); }
public static void EnsureIntegrity() { var ctx = new GalaxyStormDbContext(); var shardsRepo = new Repository<Shard>(ctx); var playersRepo = new Repository<PlayerObject>(ctx); var usersRepo = new Repository<ApplicationUser>(ctx); var planetsRepo = new Repository<Planet>(ctx); var shardService = new ShardService(playersRepo, shardsRepo); var playerService = new PlayerService(usersRepo,planetsRepo, shardsRepo, playersRepo, null); AllocatePlanets(shardService); AssignPlayerObjects(playerService); }
public string Generatereport(DateTime date) { IRepository repository = new Repository(SessionFactoryProvider); var q = (from sesion in repository.AsQueryable<Sesions>() where sesion.CreationTime == date select sesion).Single(); stream.Write("Sesijos pradzia: " + q.CreationTime + ",\nUztruko: " + q.ExecutionTime + "sekundziu,\n"); stream.Write("Vartotojo IP: " + q.userIP + ",\n"); List<URLs> q1 = (from url in repository.AsQueryable<URLs>() where url.sesion == q select url).ToList<URLs>(); stream.Write("Nuorodu kiekis: " + q1.Count + ",\n\n"); int requestCount = 0; int overalResponseTime = 0; int avgResponseTime = 0; double avgTimesOfSucces = 0; double avgTimesOfFailure = 0; int timesOfSuccesAll = 0; int timesOfFailureAll = 0; int timesOfSucces = 0; int timesOfFailure = 0; List<Responses> q2; foreach (URLs url in q1) { timesOfSucces = 0; timesOfFailure = 0; overalResponseTime = 0; q2 = (from response in repository.AsQueryable<Responses>() where response.URL == url select response).ToList<Responses>(); requestCount = q2.Count; stream.Write("URL adresas: " + url.url + ",\n"); stream.Write("Uzklausu skaicius: " + q2.Count + ",\n\n"); foreach (Responses response in q2) { overalResponseTime += response.ResponseTime; if (response.ResponseCode.ResponseCode == 200) timesOfSucces++; else timesOfFailure++; } avgResponseTime = overalResponseTime / q2.Count; stream.Write("Vidutinis atsako laikas: " + avgResponseTime + ",\n"); stream.Write("Sekmingu uzklausu skaicius: " + timesOfSucces + ",\n"); stream.Write("Nesekmingu uzklausu skaicius: " + timesOfFailure + ",\n\n"); timesOfSuccesAll += timesOfSucces; timesOfFailureAll += timesOfFailure; } avgTimesOfSucces = (double)timesOfSuccesAll / (requestCount * q1.Count) * 100; avgTimesOfFailure = (double)timesOfFailureAll / (requestCount * q1.Count) * 100; stream.Write("Visos sesijos duomenys: \n\n"); stream.Write("Sekmingu atsakymu vidurkis: " + avgTimesOfSucces + "% ,\n"); stream.Write("Nesekmingu atsakymu vidurkis: " + avgTimesOfFailure + "% ,\n"); return stream.ToString(); }
public static void CreateWeeklyInvoice(Repository repository) { var weeklyInvoiceDetails = WeeklyInvoiceDataReceiver.Get(repository.ClientsWrapper.Data); var now = GetDate(); var pdfFilename = WeeklyInvoiceFactory.Create(repository.InvoiceWrapper.Data, weeklyInvoiceDetails, repository.CompanyInformationWrapper.Data, now, repository.StorageWrapper.Data.InvoiceDirectory); FileSavedNotifier.Notify(pdfFilename); FileVisualisationRequestor.VisualiseIfRequested(pdfFilename); DirectoryVisualisationRequester.VisualiseIfRequested(pdfFilename); InvoiceEmailer.EmailIfRequested(repository, pdfFilename, weeklyInvoiceDetails, now); }