public void Process_TwoEventsWithMaximumRating_ReturnApplicableFact() { // arrange _settings = new ItHappenedSettings( new TrackSettingsForRatingFacts( 3, 30, 7), null, null); events.Add(new Event( Guid.NewGuid(), DateTime.Now - TimeSpan.FromDays(20), Guid.NewGuid(), new Customizations(new CustomizationsDto() { Rating = 7 }, new List <CustomizationType>() { CustomizationType.Rating }))); var bestEventFact = new BestEventFact(_settings); // act bestEventFact.Process(events, trackName); // assert Assert.IsTrue(bestEventFact.IsApplicable); Assert.AreEqual( $"Событие TestTrack с самым высоким рейтингом 7 произошло {events[3].CreatedAt.ToString()}", bestEventFact.Description); }
public StatisticsService(IEventRepository eventRepository, ITrackRepository trackRepository, ItHappenedSettings settings) { _eventRepository = eventRepository; _trackRepository = trackRepository; _trackStatisticsFacts = new List <IStatisticsFact> { new BestEventFact(settings), new WorstEventFact(settings) }; _generalStatisticsFacts = new List <IStatisticsFact>() { new NEventsRecordedFact(settings) }; }
public void Process_AmountOfEventsNotSatisfyRequiredCondition_ReturnNotApplicableFact() { // arrange _settings = new ItHappenedSettings( null, null, new NEventsRecordedFactSettings(3)); var nEventsRecordedFact = new NEventsRecordedFact(_settings); // act nEventsRecordedFact.Process(events, trackName); // assert Assert.IsFalse(nEventsRecordedFact.IsApplicable); }
public void Process_DaysSinceEarliestEventNotSatisfyRequiredCondition_ReturnNotApplicableFact() { // arrange _settings = new ItHappenedSettings( new TrackSettingsForRatingFacts( 3, 60, 5), null, null); var bestEventFact = new BestEventFact(_settings); // act bestEventFact.Process(events, trackName); // assert Assert.IsFalse(bestEventFact.IsApplicable); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => options.AddPolicy("ApiCorsPolicy", builder => { builder.WithOrigins("*").AllowAnyMethod().AllowAnyHeader(); })); var jwtConfig = Configuration.GetSection("JwtConfig").Get <JwtConfiguration>(); services.AddSingleton(jwtConfig); services .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters() { ValidateAudience = false, ValidateIssuer = false, ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtConfig.Secret)), ValidateLifetime = true }; }); services.AddControllers(options => { options.Filters.Add(typeof(LoggingFilter)); }); services.AddControllers(options => { options.Filters.Add(typeof(GlobalExceptionAttribute)); }); ConfigureMapper(services); RegisterDapperRepository(services); services.AddScoped <IUserService, UserService>(); services.AddScoped <ITracksService, TracksService>(); services.AddScoped <IEventService, EventService>(); services.AddScoped <IStatisticsService, StatisticsService>(); services.AddScoped(provider => ItHappenedSettings.FromJsonFile("coreappsettings.json")); services.AddSingleton <IJwtIssuer, JwtIssuer>(); services.AddControllers(); }
public void Process_EventsCountWithRatingNotSatisfyRequiredCondition_ReturnNotApplicableFact() { // arrange _settings = new ItHappenedSettings( null, new TrackSettingsForRatingFacts( 4, 30, 5 ), null); var worstEventFact = new WorstEventFact(_settings); // act worstEventFact.Process(events, trackName); // assert Assert.IsFalse(worstEventFact.IsApplicable); }
public void Process_ReturnApplicableFactForCorrectData() { // arrange _settings = new ItHappenedSettings( null, null, new NEventsRecordedFactSettings(2)); var nEventsRecordedFact = new NEventsRecordedFact(_settings); // act nEventsRecordedFact.Process(events, trackName); // assert Assert.IsTrue(nEventsRecordedFact.IsApplicable); Assert.AreEqual(Math.Log(3), nEventsRecordedFact.Priority); Assert.AreEqual( $"У вас произошло уже 3 события!", nEventsRecordedFact.Description); }
public void Process_ReturnApplicableFactForCorrectData() { // arrange _settings = new ItHappenedSettings( new TrackSettingsForRatingFacts( 3, 30, 5), null, null); var bestEventFact = new BestEventFact(_settings); // act bestEventFact.Process(events, trackName); // assert Assert.IsTrue(bestEventFact.IsApplicable); Assert.AreEqual(7, bestEventFact.Priority); Assert.AreEqual( $"Событие TestTrack с самым высоким рейтингом 7 произошло {events[2].CreatedAt.ToString()}", bestEventFact.Description); }
public BestEventFact(ItHappenedSettings settings) { _settings = settings; }
public NEventsRecordedFact(ItHappenedSettings settings) { _settings = settings; }