public void AllPredicates() { //arrange var eventFilterRequest = new EventFilterDataRequest { FromDateTime = new DateTime(2020, 10, 14, 18, 01, 00), ToDateTime = new DateTime(2019, 10, 14, 18, 00, 00), LowerLimitRating = 0.2, UpperLimitRating = 0.5, SubstringForMatching = "aaa", ScaleLowerLimit = 0.3, ScaleUpperLimit = 400, GpsLatLeftDownCorner = 15.8, GpsLngLeftDownCorner = 17.9, GpsLatRightUpperCorner = 32.4, GpsLngRightUpperCorner = 78.4 }; var filtersData = _mapper.Map <EventFilterData>(eventFilterRequest); //act var filterStringPredicates = new MssqlEventsFilter().CreateFilterMsSqlPredicates(filtersData, TableName); //assert Assert.AreEqual( $@"CAST({TableName}.HappensDate AS DATE) >= CAST('20201014 18:01:00.000' AS DATETIME) and CAST({TableName}.HappensDate AS DATE) <= CAST('20191014 18:00:00.000' AS DATETIME) and {TableName}.scale >= 0.3 and {TableName}.scale <= 400 and {TableName}.rating >= 0.2 and {TableName}.rating <= 0.5 and {TableName}.comment LIKE '%aaa%' and {TableName}.latitudeGeo >= 15.8 and {TableName}.latitudeGeo <= 32.4 and {TableName}.longitudeGeo >= 17.9 and {TableName}.longitudeGeo <= 78.4".Replace("\r\n", ""), filterStringPredicates); }
private static EventFiltrationDapperRepository EventFiltrationDapperRepository() { var dbConnectionMock = MockDapper(out var dbTransaction); var mapperConfig = new MapperConfiguration(cfg => { cfg.AddProfile(new RequestToDomainProfile(new Utf8Coder())); }); var mapper = new Mapper(mapperConfig); var filter = new MssqlEventsFilter(); var eventFiltrationRepository = new EventFiltrationDapperRepository(dbConnectionMock.Object, dbTransaction.Object, filter, mapper); return(eventFiltrationRepository); }
public void Comment() { //arrange var eventFilterRequest = new EventFilterDataRequest { SubstringForMatching = "SomeComment", }; var filtersData = _mapper.Map <EventFilterData>(eventFilterRequest); //act var filterStringPredicates = new MssqlEventsFilter().CreateFilterMsSqlPredicates(filtersData, TableName); //assert Assert.AreEqual($"{TableName}.comment LIKE '%SomeComment%'", filterStringPredicates); }
public void ScaleFilterLowerBound() { //arrange var eventFilterRequest = new EventFilterDataRequest { ScaleLowerLimit = 2, }; var filtersData = _mapper.Map <EventFilterData>(eventFilterRequest); //act var filterStringPredicates = new MssqlEventsFilter().CreateFilterMsSqlPredicates(filtersData, TableName); //assert Assert.AreEqual($"{TableName}.scale >= 2", filterStringPredicates); }
public void RatingFilterUpperAndLowerBound() { //arrange var eventFilterRequest = new EventFilterDataRequest { LowerLimitRating = 2, UpperLimitRating = 5.5 }; var filtersData = _mapper.Map <EventFilterData>(eventFilterRequest); //act var filterStringPredicates = new MssqlEventsFilter().CreateFilterMsSqlPredicates(filtersData, TableName); //assert Assert.AreEqual($"{TableName}.rating >= 2 and {TableName}.rating <= 5.5", filterStringPredicates); }
public void DateFilterLowerBound() { //arrange var eventFilterRequest = new EventFilterDataRequest { FromDateTime = new DateTime(2019, 10, 14, 18, 01, 00), }; var filterStringPredicates = _mapper.Map <EventFilterData>(eventFilterRequest); //act var filter = new MssqlEventsFilter().CreateFilterMsSqlPredicates(filterStringPredicates, TableName); // Assert.AreEqual($"CAST({TableName}.HappensDate AS DATE) >= CAST('20191014 18:01:00.000' AS DATETIME)", filter); }
public void DateFilterUpperBound() { //arrange var eventFilterRequest = new EventFilterDataRequest { ToDateTime = new DateTime(2020, 10, 14, 18, 00, 00) }; var filtersData = _mapper.Map <EventFilterData>(eventFilterRequest); //act var filterStringPredicates = new MssqlEventsFilter().CreateFilterMsSqlPredicates(filtersData, TableName); // Assert.AreEqual($"CAST({TableName}.HappensDate AS DATE) <= CAST('20201014 18:00:00.000' AS DATETIME)", filterStringPredicates); }
public void GetTagBounds() { //arrange var eventFilterRequest = new EventFilterDataRequest { GpsLatLeftDownCorner = 10.0, GpsLngLeftDownCorner = 11.0, GpsLatRightUpperCorner = 20.0, GpsLngRightUpperCorner = 21.0 }; var filtersData = _mapper.Map <EventFilterData>(eventFilterRequest); //act var filterStringPredicates = new MssqlEventsFilter().CreateFilterMsSqlPredicates(filtersData, TableName); //assert Assert.AreEqual( $"{TableName}.latitudeGeo >= 10 and {TableName}.latitudeGeo <= 20 and {TableName}.longitudeGeo >= 11 and {TableName}.longitudeGeo <= 21", filterStringPredicates); }
public void EventFiltration() { //arrange var dbConnectionMock = new Mock <IDbConnection>(); var dbTransaction = new Mock <DbTransaction>(); var trackerId = Guid.NewGuid(); var userId = Guid.NewGuid(); var events = new List <Event> { new Event(Guid.NewGuid(), userId, trackerId, DateTimeOffset.UtcNow, new EventCustomParameters( Option <Photo> .None, Option <double> .Some(1.0), Option <double> .None, Option <GeoTag> .None, Option <Comment> .None)), new Event(Guid.NewGuid(), userId, trackerId, DateTimeOffset.UtcNow, new EventCustomParameters( Option <Photo> .None, Option <double> .Some(11.0), Option <double> .None, Option <GeoTag> .None, Option <Comment> .None)), }; dbConnectionMock.SetupDapper(c => c.Query <Event>( It.IsAny <string>(), null, null, true, null, null)) .Returns(events); var eventFilterRequest = new EventFilterDataRequest { FromDateTime = new DateTime(2020, 10, 14, 18, 01, 00), ToDateTime = new DateTime(2019, 10, 14, 18, 00, 00), LowerLimitRating = 0.5, UpperLimitRating = 0.5, SubstringForMatching = "aaa", ScaleLowerLimit = 0.3, ScaleUpperLimit = 0.2, GpsLatLeftDownCorner = 15.8, GpsLngLeftDownCorner = 17.9, GpsLatRightUpperCorner = 32.4, GpsLngRightUpperCorner = 78.4 }; var mapperConfig = new MapperConfiguration(cfg => { cfg.AddProfile(new RequestToDomainProfile(new Utf8Coder())); }); var mapper = new Mapper(mapperConfig); var filtersData = mapper.Map <EventFilterData>(eventFilterRequest); var filter = new MssqlEventsFilter(); //act // var eventFiltration = new EventFiltration(dbConnectionMock.Object, dbTransaction.Object, filter); //useless moq. Always get arranged events // var filteredEventsResult = // eventFiltration.GetAllFilteredEvents(Guid.NewGuid(), Guid.NewGuid(), filtersData); //assert //Object Event not fully constructed. When event have private parameterless constructor field EventCustomParameters is null }