public async Task CanDeleteExistingEntry() { using (var context = new AppDbContext(_options)) { var service = new EntryService(context); var entry = new Entry { Title = "Delete Me", Body = "Boring stuff" }; var journal = new Journal { Id = 1, Title = "My Journal", Entries = new List <Entry>() }; journal.Entries.Add(entry); context.Journals.Add(journal); await context.SaveChangesAsync(); var result = await service.Delete(new EntryDeletionDto { EntryId = entry.Id, JournalId = journal.Id }); result.Should().BeGreaterThan(0, "because more than one object was updated"); } }
public void TestAddEntryToLog_ShouldCallFactoryCreateLogEntry(string content, int logId) { // Arrange var mockedLogService = new Mock <ILogService>(); var date = new DateTime(); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); mockedDateTimeProvider.Setup(p => p.GetCurrentTime()) .Returns(date); var mockedFactory = new Mock <ILogEntryFactory>(); var mockedRepository = new Mock <IRepository <LogEntry> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var service = new EntryService(mockedLogService.Object, mockedDateTimeProvider.Object, mockedFactory.Object, mockedRepository.Object, mockedUnitOfWork.Object); // Act service.AddEntryToLog(content, logId, null); // Assert mockedFactory.Verify(f => f.CreateLogEntry(content, date, logId), Times.Once); }
public EntryServiceTests() { _mockEntryRepository = new Mock <IEntryRepository>(); _mockBase64Validator = new Mock <IBase64Validator>(); _objectToTest = new EntryService(_mockEntryRepository.Object, _mockBase64Validator.Object); }
// GET: Teams/Create public ActionResult Create() { TeamCreateViewModel teamCreateViewModel = new TeamCreateViewModel(); var entryList = new List <EntryDropDownListViewModel>(); var mapperConfig = new MapperConfiguration(cfg => { cfg.CreateMap <EntryDTO, EntryDropDownListViewModel>(); }); using (var entryService = new EntryService()) { try { var user = SessionLoginUtilities.GetLoggedInUser(Session); var allEntryDto = user.Permissions.GetEntryAdminPermissons <EntryDTO>(); if (allEntryDto == null) { throw new NullReferenceException(); } var mapper = mapperConfig.CreateMapper(); mapper.Map(allEntryDto, entryList); ViewBag.EntryDropDownList = new SelectList(entryList.OrderBy(b => b.FullEntryName), "Id", "FullEntryName"); return(View()); } catch (Exception e) { TempData["ResultMessage"] = e.Message; return(View("Error")); } } }
public async Task MoveEntryToJournal_JournalFound_EntryMoved() { // Arrange var destJournal = CreateJournal(); destJournal.Id = 2L; destJournal.Title = "Journal 2"; var srcJournal = CreateJournal(); var entry = CreateEntry(); entry.Journal = srcJournal; entry.JournalId = srcJournal.Id; srcJournal.Entries.Add(entry); _context.Journals.AddRange(srcJournal, destJournal); await _context.SaveChangesAsync(); // Act var service = new EntryService(_context); var result = await service.MoveEntryToJournal(entry.Id, destJournal.Id); // Assert result.JournalId.Should().Be(destJournal.Id); }
public ActionResult Create(PocoClasses.Entries.Team newTeam, int entryId) { Mapper.Initialize(cfg => cfg.CreateMap <PocoClasses.Entries.Team, Team>()); Team team = Mapper.Map <Team>(newTeam); team.EntryId = entryId; if (ModelState.IsValid) { using (var context = new TeamContext()) { var service = new TeamService(context); service.Add(team); } using (var context = new RaceEntryContext()) { var service = new RaceEntryService(context); service.Add(team.Id, newTeam.EventId); } Entry entry; using (var context = new EntryContext()) { var service = new EntryService(new RosContext <Entry>()); entry = service.GetById(entryId); } return(RedirectToAction("Index", entry)); } return(View(team)); }
public static void RemoveExistingEntryById() { Console.Clear(); var entries = _repository.GetAll().ToList(); if (entries.Count() == 0) { Console.WriteLine("There are no entries available"); } else { foreach (var item in entries) { DisplayEntryColorBasedOnType(item); } Console.ResetColor(); Console.WriteLine(); Console.WriteLine("Please type id of entry to remove: "); int id; while (!int.TryParse(Console.ReadLine(), out id)) { Console.WriteLine("Please enter valid id:"); } ; IEntryService entryService = new EntryService(_repository); entryService.RemoveEntryById(id); Console.WriteLine(Environment.NewLine + "Entry removed"); } ReturnToMenuMessage(); }
public async Task GetAllByJournal_JournalFound_ReturnsEntries() { // Arrange var journal = CreateJournal(); Entry entry; for (var i = 0; i < 5; i++) { entry = CreateEntry(); entry.Journal = journal; entry.JournalId = journal.Id; journal.Entries.Add(entry); } _context.Journals.Add(journal); await _context.SaveChangesAsync(); // Act var service = new EntryService(_context); var result = await service.GetAllByJournal(journal.Id); // Assert result.Should().NotBeNullOrEmpty(); result.Should().HaveCount(5); }
public void RegisterMotorcycle_WithoutCC_ShouldReturnException() { // Arrange (preparación, organizar) var entryBuilder = new EntryDTOBuilder(); DtoEntry entry = entryBuilder .WithCC(null) .Build(); // cuando se ejecute este método en el entry service va a retornar true en la validacion de ExistsQuotaByVehicleType _cellService.Setup(cs => cs.ExistsQuotaByVehicleType(VehicleTypeEnum.motorcycle)).Returns(true); _placaService.Setup(ps => ps.GetLastNumberOfIdVehicle(entry.IdVehicleType, entry.IdVehicle)).Returns("5"); var entryService = new EntryService(entryRepository.Object, _cellService.Object, _departureService.Object, _placaService.Object); // Act try { entryService.RegistryVehicle(entry); } catch (Exception e) { var message = "Falta la información del cilindraje de la motocicleta"; // Assert (confirmacion) Assert.IsInstanceOfType(e, typeof(EntryException)); Assert.AreEqual(e.Message, message); } }
public void TestEditEntry_RepositoryReturnsEntry_ShouldReturnCorrectly(int entryId, string newContent) { // Arrange var mockedLogService = new Mock <ILogService>(); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var mockedFactory = new Mock <ILogEntryFactory>(); var entry = new LogEntry(); var mockedRepository = new Mock <IRepository <LogEntry> >(); mockedRepository.Setup(r => r.GetById(It.IsAny <object>())).Returns(entry); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var service = new EntryService(mockedLogService.Object, mockedDateTimeProvider.Object, mockedFactory.Object, mockedRepository.Object, mockedUnitOfWork.Object); // Act var result = service.EditEntry(entryId, newContent); // Assert Assert.AreSame(entry, result); }
public void GetLastEntryByVehicleBadId_ShouldReturnNull() { // Arrange (preparación, organizar) var entryEntity = new EntryEntity { CC = null, EntryTime = DateTime.Now, Id = Guid.NewGuid().ToString(), IdVehicle = "SFL55D", IdVehicleType = VehicleTypeEnum.car }; var entryList = new List <EntryEntity> { entryEntity }; var id = entryEntity.IdVehicle; entryRepository.Setup(er => er.List(er => er.IdVehicle == id)).Returns(entryList); var entryServiceClass = new EntryService(entryRepository.Object, _cellService.Object, _departureService.Object, _placaService.Object); // Act var result = entryServiceClass.GetLastEntryByVehicleId("ZFL55D"); // Assert Assert.IsNull(result); }
public static void AddNewOutcome() { Console.Clear(); Console.WriteLine("New outcome:"); Console.WriteLine("Enter outcome name: "); string name = Console.ReadLine(); Console.WriteLine("Enter amount:"); decimal amount; while (!decimal.TryParse(Console.ReadLine(), out amount)) { Console.WriteLine("Please enter valid amount: "); } ; Console.WriteLine("Enter date (YYYY-MM-DD): "); DateTime date; while (!DateTime.TryParse(Console.ReadLine(), out date)) { Console.WriteLine("Please enter valid date:"); } ; IEntryService entryService = new EntryService(_repository); entryService.AddNewOutcome(amount, name, date); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("New outcome added"); ReturnToMenuMessage(); }
static ServiceLocator() { AddressService = new AddressService(); BoatService = new BoatService(); ClubService = new ClubService(); UserService = new UserService(); EntryService = new EntryService(); RaceEventService = new RaceEventService(); RegattaService = new RegattaService(); SocialEventService = new SocialEventService(); TeamService = new TeamService(); EmailService = new EmailService(); PhoneNumberService = new PhoneNumberService(); RegisteredUserService = new RegisteredUserService(); ResultService = new ResultService(); UserRoleService = new UserRoleService(); ClubsUsersUserRolesJunctionsService = new Clubs_Users_UserRoles_JunctionsService(); RegattasUsersUserRolesJunctionsService = new Regattas_Users_UserRoles_JunctionsService(); RegisteredUserSocialEventService = new RegisteredUser_SocialEventService(); TeamRaceEventService = new Team_RaceEventService(); TeamRegisteredUserService = new Team_RegisteredUserService(); BoatService = new BoatService(); SocialEventsUsersUserRolesJunctionsService = new SocialEvents_Users_UserRoles_JunctionsService(); RaceEventsUsersUserRolesJunctionsService = new RaceEvents_Users_UserRoles_JunctionsService(); ClubsEmailsService = new ClubsEmailsService(); ClubsPhoneNumbersService = new ClubsPhoneNumbersService(); }
public void TestEditEntry_RepositoryReturnsEntry_ShouldCallRepositoryUpdate(int entryId, string newContent) { // Arrange var mockedLogService = new Mock <ILogService>(); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var mockedFactory = new Mock <ILogEntryFactory>(); var entry = new LogEntry(); var mockedRepository = new Mock <IRepository <LogEntry> >(); mockedRepository.Setup(r => r.GetById(It.IsAny <object>())).Returns(entry); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var service = new EntryService(mockedLogService.Object, mockedDateTimeProvider.Object, mockedFactory.Object, mockedRepository.Object, mockedUnitOfWork.Object); // Act service.EditEntry(entryId, newContent); // Assert mockedRepository.Verify(r => r.Update(entry), Times.Once); }
private EntryService CreateEntryService() { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new EntryService(userId); return(service); }
public void TestAddEntryToLog_ShouldCallServiceAddEntryToLog(string content, int logId) { // Arrange var mockedLogService = new Mock <ILogService>(); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var entry = new LogEntry(); var mockedFactory = new Mock <ILogEntryFactory>(); mockedFactory.Setup(f => f.CreateLogEntry(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <int>())) .Returns(entry); var mockedRepository = new Mock <IRepository <LogEntry> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var service = new EntryService(mockedLogService.Object, mockedDateTimeProvider.Object, mockedFactory.Object, mockedRepository.Object, mockedUnitOfWork.Object); // Act service.AddEntryToLog(content, logId, null); // Assert mockedLogService.Verify(s => s.AddEntryToLog(logId, entry, null), Times.Once); }
public Tags(double lat, double longitud) { InitializeComponent(); MyMap.CustomPins = new List <CustomPin>(); Device.BeginInvokeOnMainThread(async() => { EntryService entryService = new EntryService(); List <GeoTaggerEntry> entries = await entryService.GetLastEntries(); foreach (GeoTaggerEntry entry in entries) { var thisPosition = new Position(double.Parse(entry.Lat), double.Parse(entry.Long)); // Latitude, Longitude var pin = new CustomPin { Type = PinType.Generic, Position = thisPosition, Label = entry.Text, Url = entry.Link }; MyMap.CustomPins.Add(pin); MyMap.Pins.Add(pin); } }); var mapPosition = new Position(-34, -58); MyMap.MoveToRegion(MapSpan.FromCenterAndRadius(mapPosition, Distance.FromMiles(1))); }
public void RegisterCar_WithBadIdVehicleFormat_ShouldReturnException() { // Arrange (preparación, organizar) var entryBuilder = new EntryDTOBuilder() .WithVehicleId("SFL55A") .WithVehicleType(VehicleTypeEnum.car); DtoEntry entry = entryBuilder.Build(); _cellService.Setup(cs => cs.ExistsQuotaByVehicleType(VehicleTypeEnum.car)).Returns(true); var entryService = new EntryService(entryRepository.Object, _cellService.Object, _departureService.Object, _placaService.Object); // Act try { entryService.RegistryVehicle(entry); } catch (Exception e) { var message = "Hubo un problema al leer la placa del vehículo. Verifique el tipo de vehículo e intente de nuevo"; // Assert (confirmacion) Assert.IsInstanceOfType(e, typeof(EntryException)); Assert.AreEqual(e.Message, message); } }
public void RegisterVehicle_WithoutCellAvaliable_ShouldReturnException() { // Arrange (preparación, organizar) var entryBuilder = new EntryDTOBuilder() .WithVehicleId("SFL555") .WithVehicleType(VehicleTypeEnum.car); _cellService.Setup(cs => cs.ExistsQuotaByVehicleType(VehicleTypeEnum.car)).Returns(false); var entryService = new EntryService(entryRepository.Object, _cellService.Object, _departureService.Object, _placaService.Object); DtoEntry entry = entryBuilder.Build(); // Act try { entryService.RegistryVehicle(entry); } catch (Exception e) { var message = "No hay cupos disponibles"; // Assert (confirmacion) Assert.IsInstanceOfType(e, typeof(CellException)); Assert.AreEqual(e.Message, message); } }
// GET: Entry public ActionResult Index() { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new EntryService(userId); var model = service.GetEntries(); return(View(model)); }
public async void ThrowsGivenNullEntryServiceArguments() { var entryService = new EntryService(null, _mockEntryRepo.Object); await Assert.ThrowsAsync <ArgumentNullException>( async() => await entryService.SetEntryAsync(null) ); }
public async void ThrowsGivenInvalidEntryId() { var entryService = new EntryService(null, _mockEntryRepo.Object); await Assert.ThrowsAsync <EntryNotFoundException>( async() => await entryService.GetEntryById(_invalidId) ); }
public void GetById_EntryNotFound_ThrowsEntryNotFoundException() { var service = new EntryService(_context); service .Invoking(s => s.GetById(1L)) .Should() .Throw <EntryNotFoundException>(); }
public void Update_EntryNotFound_ThrowsException() { var service = new EntryService(_context); service .Invoking(s => s.Update(new EntryDto())) .Should() .Throw <EntryNotFoundException>(); }
public void Add_JournalNotFound_ThrowsJournalNotFoundException() { var service = new EntryService(_context); service .Invoking(s => s.Add(1L, new EntryDto())) .Should() .Throw <JournalNotFoundException>(); }
public ActionResult Badges() { EntryService entryService = CreateEntryService(); var userId = User.Identity.GetUserId(); var model = entryService.GetEntryAndGoalCount(userId); return(View(model)); }
public async Task GetAllByJournal_JournalNotFound_ReturnsNull() { // Act var service = new EntryService(_context); var result = await service.GetAllByJournal(1L); // Assert result.Should().BeNull(); }
public void Register() { //Setup the connection with the message broker ////////////////// TextWriter oldOut = Console.Out; ///////////////// ConnectionFactory factory = new ConnectionFactory(); IProtocol protocol = Protocols.AMQP_0_9_1; factory.VirtualHost = virtualHost; factory.UserName = userName; factory.Password = password; factory.HostName = hostName; factory.Port = port; factory.Protocol = protocol; IConnection conn = factory.CreateConnection(); IModel channel = conn.CreateModel(); uint messageCount = GetMessageCount(factory, queueName); EntryService.CreateGeneralAuditoria(Environment.MachineName, Environment.UserName, messageCount); if (messageCount == 0) { EntryService.CreateEntryAuditoria(Environment.MachineName, Environment.UserName, new Entries()); Environment.Exit(0); } else { int messageCountIndex = 0; var consumer = new EventingBasicConsumer(channel); consumer.Received += (ch, ea) => { var body = ea.Body; string message = Encoding.UTF8.GetString(body); EntryDTO result = JsonConvert.DeserializeObject <EntryDTO>(message); EntryService.CreateEntryAuditoria(Environment.MachineName, Environment.UserName, result.entries); if (EntryService.CreateNotaEntry(result.entries)) { channel.BasicAck(ea.DeliveryTag, false); } messageCountIndex++; }; if (messageCountIndex == messageCount) { Environment.Exit(0); } String consumerTag = channel.BasicConsume(queueName, false, consumer); } }
public void MoveEntryToJournal_JournalNotFound_ThrowsMoveEntryException() { // Act & assert var service = new EntryService(_context); service .Invoking(s => s.MoveEntryToJournal(1L, 1L)) .Should() .Throw <MoveEntryException>(); }
static void Main6(string[] args) { DataTable dt = ExcelHelper.GetDataTable("D:/培训导入.xlsx"); IEntryService entryService = new EntryService(); bool b = entryService.EntryImport(3, 14, 38, dt); Console.WriteLine(b); Console.ReadKey(); }
public static IEntryService SetupEntryService() { var entryRepository = new Mock<IEntryRepository>(); var locationRepository = new Mock<ILocationRepository>(); var tagRepository = new Mock<ITagRepository>(); var timeLineServiceStub = new Mock<ITimelineColorService>(); var timeServiceStub = new Mock<ITimeService>(); var scopeStub = new Mock<IScope>(); var entryService = new EntryService( entryRepository.Object, locationRepository.Object, tagRepository.Object, timeLineServiceStub.Object, timeServiceStub.Object, scopeStub.Object); return entryService; }
protected override void ExecuteTest() { var service = new EntryService(userEntryProvider); actualUrl = service.Get(EntryRequest.Create(suppliedLocalEducationAgencyId, null)); }
protected override void ExecuteTest() { try { var service = new EntryService(userEntryProvider); actualModel = service.Get(EntryRequest.Create(suppliedLocalEducationAgencyId, suppliedSchoolId)); } catch (Exception ex) { actualException = ex; } }