public async override Task InitializeAsync(object navigationData) { var service = new MockDataService(); Movies = new ObservableCollection <Movie>(await service.GetMoviesAsync()); Series = new ObservableCollection <Serie>(await service.GetSeriesAsync()); }
public List <Attendance> GetAttendanceListFor(int gameNumber) { MockDataService service = new MockDataService(); List <Member> members = service.Members().ToList(); List <Ticket> tickets = service.Tickets().ToList(); List <Product> products = service.Products().ToList(); List <Attendance> attendanceList = new List <Attendance>(); for (int i = 0; i < members.Count; i++) { attendanceList.Add(new Attendance() { Barcode = "N/A", MemberId = members[i].Id }); } for (int i = 0; i < tickets.Count; i++) { attendanceList.Add(new Attendance() { Barcode = tickets[i].Barcode, MemberId = 0 }); } return(attendanceList); }
public AppViewModel() { var dataService = new MockDataService(); BookVM = new BookViewModel(dataService); CurrentView = BookVM; }
public static List <DTOEvent> GetMovies() { using (var context = GetNewContext()) { var list = new List <DTOEvent>(); list = context.Events .AsNoTracking() .Include(x => x.Showings) .OrderByDescending(x => x.Rating) .OrderByDescending(x => x.Name) .Where(x => x.EventType == "Фильм") .Select(x => new DTOEvent { Id = x.IDEvent, Name = x.Name, Description = x.Description, Rating = x.Rating, Website = x.Website, Showings = x.Showings.Select(s => new DTOShowing { Id = s.IDShowing, Description = s.Description, ReleaseDate = s.ReleaseDate, EndDate = s.EndDate }) .ToList() }) .ToList(); if (list.Count == 0) { return(MockDataService.GetMockMovies()); } return(list); } }
public ActionResult <PageListOutput <Student> > Query(StudentQueryInput queryInput) { PageListOutput <Student> output = new PageListOutput <Student>(); MockDataService service = new MockDataService(); var query = service.GetStudents(); if (!string.IsNullOrWhiteSpace(queryInput.Name)) { query = query.Where(o => o.Name.Contains(queryInput.Name)).ToList(); } if (queryInput.CreateFrom.HasValue) { query = query.Where(o => o.CreateTime >= queryInput.CreateFrom.Value).ToList(); } if (queryInput.CreateTo.HasValue) { query = query.Where(o => o.CreateTime <= queryInput.CreateTo.Value).ToList(); } int skip = (queryInput.Page - 1) * queryInput.PageSize; output.Total = query.Count(); output.Data = query.Skip(skip).Take(queryInput.PageSize).ToList(); return(output); }
public ResponseModel <UserHostService.User> GetCurrentAuthenticated() { IDataService ds = new MockDataService(); var response = new ResponseModel <UserHostService.User>(); var data = new UserHostService.User(); var statusCode = new HttpStatusCode(); var identity = (ClaimsIdentity)User.Identity; try { data = ds.GetUserById(Convert.ToInt32(identity.Claims.Where(x => x.Type == "IdUser").FirstOrDefault().Value)); response.Success = true; statusCode = data == null ? HttpStatusCode.NoContent : HttpStatusCode.OK; } catch (Exception ex) { response.Success = false; response.Error = ex.Message; statusCode = HttpStatusCode.InternalServerError; } response.Data = data; return(SendResponse(response, statusCode)); }
public override Task OnActivateAsync() { Console.WriteLine($"{Source} :: OnActivateAsync PK {this.GetPrimaryKeyString()}"); var abilities = MockDataService.GetHeroesAbilities().Where(x => x.HeroId == this.GetPrimaryKeyString()).ToList(); return(Set(abilities)); }
public void Test_VoltageStats() { var dataService = new MockDataService(); var spg = new SparkPlugGenerator(new MockLogger(), dataService, publishTopic); var inputMqtt = new MockMQTTWrapper(); var outputMqtt = new MockMQTTWrapper(); var deviceEUI = "123"; inputMqtt.MessageReceived += spg.ProcessMessage; spg.MessageProcessed += outputMqtt.Publish; outputMqtt.MessagePublished += OnMessagePublished; var voltageStats = new Ppuplink.VoltageStatsMessage() { Deviceeui = deviceEUI, Timesent = 1612234855, Starttime = "2021/01/01", Stoptime = "2021/01/02", Phaseid = 1, H0213 = 1, H213215 = 1, H215217 = 0, H217219 = 10, H219221 = 2, H221223 = 5, H223225 = 0, H225227 = 1, H227229 = 4, H229231 = 0, H231233 = 12, H233235 = 500, H235237 = 2, H237239 = 0, H239241 = 2, H241243 = 0, H243245 = 0, H245247 = 0, H247249 = 0, H249300 = 1, Mean = 12.4, Variance = 234.6 }; // trigger DBIRTH and voltagestats var topic = $"application/powerpilot/uplink/voltagestats/{deviceEUI}"; inputMqtt.InjectMessage(new MQTTMessageArgs(topic, voltageStats.ToByteArray())); Thread.Sleep(10); var messages = outputMqtt.GetMessagesReceived(); // expect voltagestats var voltagestats = messages.Find(m => m.Topic == $"spBv1.0/DTX/{SparkPlugMessageTypes.DDATA}/PowerPilotCS/{deviceEUI}"); Assert.NotNull(voltagestats); var payload = Payload.Parser.ParseFrom(voltagestats.Payload); Assert.Equal(24, payload.Metrics.Count); }
protected override IDataService CreateInstance(IContext context) { Console.WriteLine("MockDataServiceProvider.CreateInstance"); var service = new MockDataService(); // do complex initialization return(service); }
public AppViewModel() { var dataService = new MockDataService(); var dialogService = new WindowDialogService(); BookVM = new BookViewModel(dataService, dialogService); CurrentView = BookVM; }
void InitData() { Albums = MockDataService.GetAlbums(); Playlists = MockDataService.GetPlaylists(); Songs = MockDataService.GetSongs(); Artists = MockDataService.GetArtists(); Podcasts = MockDataService.GetPodcasts(); SearchCategories = MockDataService.GetSearchCategories(); }
public AppViewModel() { //Quando arriveranno i dati reali basterà sostituire il service che li carica in questo punto var dataService = new MockDataService(); BookVM = new BookViewModel(dataService); CurrentView = BookVM; }
public Hero AddHero() { Console.WriteLine(">>> Hero::Adding Hero"); var hero = MockDataService.GetHeroes().RandomElement(); _heroes.Add(hero); _messageStream.OnNext(hero); return(hero); }
public void InitializeDataTest() { // Arrange var mockDataService = new MockDataService(); var mockNavigationService = new MockNavigationService(); // Act var vm = new ProductsViewModel(mockDataService, mockNavigationService); // Assert Assert.True(vm.Products.Count == 3); }
private void ex5_WithMethod() { var kernel = new StandardKernel(); kernel.Bind <IDataService>().ToMethod(c => { Console.WriteLine("Creating data service"); var service = new MockDataService(); return(service); }); kernel.Get <IDataService>(); }
public ActionResult <PageListOutput <Student> > Get(int page, int pageSize) { PageListOutput <Student> output = new PageListOutput <Student>(); MockDataService service = new MockDataService(); int skip = (page - 1) * pageSize; output.Total = service.GetStudents().Count(); output.Data = service.GetStudents().Skip(skip).Take(pageSize).ToList(); return(output); }
public void EditCommand_DisplaysNewDialog() { //arrange var mockDialgoService = new MockDialogService(); var mockDataService = new MockDataService(); var sut = new MainWindowViewModel(mockDialgoService, mockDataService); //act sut.EditCommand.Execute(null); //assert Assert.IsTrue(mockDialgoService.Was_ShowPatientDetailDialog_Called); }
public void NavigationTest() { // Arrange var mockDataService = new MockDataService(); var mockNavigationService = new MockNavigationService(); var vm = new ProductsViewModel(mockDataService, mockNavigationService); // Act vm.GoToDetailsPage(new Product()); // Assert Assert.True(mockNavigationService.IsNavigated); }
public void TestMethod1() { // Arrange var mockDataService = new MockDataService(); var repo = new DataRepository(); var games = mockDataService.Games(); // Act var attendanceList = repo.GetAttendanceListFor(games.First().Id); // Assert Assert.IsNotNull(attendanceList); }
public IList <VideoInfo> GetMockVideoInfo(PlaylistData playlistData) { var ds = new MockDataService(); var completion = new ManualResetEvent(false); IList <VideoInfo> result = null; ds.GetVideoInfo(playlistData, (videoInfo, err) => { result = videoInfo; completion.Set(); }); completion.WaitOne(); return(result); }
public void GetAttendaceListByGameSeason() { // Arrange var mockDataService = new MockDataService(); var repo = new DataRepository(); var games = mockDataService.Games(); var seasons = mockDataService.Seasons(); // Act var attendanceList = repo.GetAttendanceListFor(games.First().Id, seasons.First().Id); // Assert Assert.IsNotNull(attendanceList); }
public PlaylistData GetMockPlaylistData() { var ds = new MockDataService(); PlaylistData result = null; var completion = new ManualResetEvent(false); ds.GetBBCPlaylistData((playlistData, err) => { result = playlistData; completion.Set(); }); completion.WaitOne(); return(result); }
public Uri GetMockVideoUri(string videoId) { var ds = new MockDataService(); Uri result = null; var completion = new ManualResetEvent(false); ds.GetYoutubeVideoUri(videoId, (youTubeUri, err) => { result = youTubeUri; completion.Set(); }); completion.WaitOne(); return(result); }
public void Test_Uplink() { var dataService = new MockDataService(); var spg = new SparkPlugGenerator(new MockLogger(), dataService, publishTopic); var inputMqtt = new MockMQTTWrapper(); var outputMqtt = new MockMQTTWrapper(); var deviceEUI = "123"; inputMqtt.MessageReceived += spg.ProcessMessage; spg.MessageProcessed += outputMqtt.Publish; outputMqtt.MessagePublished += OnMessagePublished; var uplinkMsg = new Ppuplink.UplinkMessage() { Deviceeui = deviceEUI, Timesent = 1612234855, Fctn = 1, Messageid = 1, Rssi = 10, Snr = -10, Frequency = 8000, Messagetype = 32, Dr = 200, Rawdata = "0A86454EFA", Resent = 0 }; dataService.Uplink = uplinkMsg; // trigger DBIRTH and uplink var topic = $"application/powerpilot/uplink/uplink/{deviceEUI}"; inputMqtt.InjectMessage(new MQTTMessageArgs(topic, uplinkMsg.ToByteArray())); Thread.Sleep(10); var messages = outputMqtt.GetMessagesReceived(); // expect uplink var uplink = messages.Find(m => m.Topic == $"spBv1.0/DTX/{SparkPlugMessageTypes.DDATA}/PowerPilotCS/{deviceEUI}"); Assert.NotNull(uplink); var payload = Payload.Parser.ParseFrom(uplink.Payload); Assert.Equal(4, payload.Metrics.Count); }
public void Test_Alarm_PowerFail() { var dataService = new MockDataService(); var spg = new SparkPlugGenerator(new MockLogger(), dataService, publishTopic); var inputMqtt = new MockMQTTWrapper(); var outputMqtt = new MockMQTTWrapper(); var deviceEUI = "123"; inputMqtt.MessageReceived += spg.ProcessMessage; spg.MessageProcessed += outputMqtt.Publish; outputMqtt.MessagePublished += OnMessagePublished; var alarmMessage = new Ppuplink.AlarmMessage() { Deviceeui = deviceEUI, Timesent = 1612234855, Alarmtype = "powerfailalarm", Phaseid = 1, Value = 0 }; // trigger DBIRTH and alarm var topic = $"application/powerpilot/uplink/alarm/{deviceEUI}"; inputMqtt.InjectMessage(new MQTTMessageArgs(topic, alarmMessage.ToByteArray())); Thread.Sleep(10); var messages = outputMqtt.GetMessagesReceived(); // expect alarm var alarm = messages.Find(m => m.Topic == $"spBv1.0/DTX/{SparkPlugMessageTypes.DDATA}/PowerPilotCS/{deviceEUI}"); Assert.NotNull(alarm); var payload = Payload.Parser.ParseFrom(alarm.Payload); Assert.Single(payload.Metrics); Assert.Equal($"{Alarm.TYPE}/1/{Alarm.POWER_FAIL}", payload.Metrics[0].Name); // expect DDEATH var ddeath = messages.Find(m => m.Topic == $"spBv1.0/DTX/{SparkPlugMessageTypes.DDEATH}/PowerPilotCS/{deviceEUI}"); Assert.NotNull(ddeath); }
private List <Cardholder> GetCardholders() { var cardholders = MockDataService.Cardholders(100); var result = new List <Cardholder>(); foreach (var cardholder in cardholders) { if (cardholder.UserType == SHCCardType.Employee) { result.Add(MockDataService.GenerateEmployee(cardholder)); } else if (cardholder.UserType == SHCCardType.Tenant) { result.Add(MockDataService.GenerateTenant(cardholder)); } } return(result); }
public void Test_Alarm_NormalVoltage() { var dataService = new MockDataService(); var spg = new SparkPlugGenerator(new MockLogger(), dataService, publishTopic); var inputMqtt = new MockMQTTWrapper(); var outputMqtt = new MockMQTTWrapper(); var deviceEUI = "123"; inputMqtt.MessageReceived += spg.ProcessMessage; spg.MessageProcessed += outputMqtt.Publish; outputMqtt.MessagePublished += OnMessagePublished; var alarmMessage = new Ppuplink.AlarmMessage() { Deviceeui = deviceEUI, Timesent = 1612234855, Alarmtype = "normalvoltage", Phaseid = 1, Value = 237.3 }; // trigger DBIRTH and alarm var topic = $"application/powerpilot/uplink/alarm/{deviceEUI}"; inputMqtt.InjectMessage(new MQTTMessageArgs(topic, alarmMessage.ToByteArray())); Thread.Sleep(10); var messages = outputMqtt.GetMessagesReceived(); // expect alarm var alarm = messages.Find(m => m.Topic == $"spBv1.0/DTX/{SparkPlugMessageTypes.DDATA}/PowerPilotCS/{deviceEUI}"); Assert.NotNull(alarm); var payload = Payload.Parser.ParseFrom(alarm.Payload); Assert.Single(payload.Metrics); Assert.Equal($"{Alarm.TYPE}/1/{Alarm.VOLTAGE_NORMAL}", payload.Metrics[0].Name); // should have extra DBIRTH for coming back to life Assert.Equal(3, outputMqtt.GetNumPublishedMessages()); }
public void Test_PQ() { var dataService = new MockDataService(); var spg = new SparkPlugGenerator(new MockLogger(), dataService, publishTopic); var inputMqtt = new MockMQTTWrapper(); var outputMqtt = new MockMQTTWrapper(); var deviceEUI = "123"; inputMqtt.MessageReceived += spg.ProcessMessage; spg.MessageProcessed += outputMqtt.Publish; outputMqtt.MessagePublished += OnMessagePublished; var pqMsg = new Ppuplink.PQMessage() { Deviceeui = deviceEUI, Timesent = 1612234855, Currentmax = 10, Voltagemax = 250.0, Phaseid = 1 }; dataService.PQ = pqMsg; // trigger DBIRTH and PQ var topic = $"application/powerpilot/uplink/pq/{deviceEUI}"; inputMqtt.InjectMessage(new MQTTMessageArgs(topic, pqMsg.ToByteArray())); Thread.Sleep(10); var messages = outputMqtt.GetMessagesReceived(); // expect pq var pq = messages.Find(m => m.Topic == $"spBv1.0/DTX/{SparkPlugMessageTypes.DDATA}/PowerPilotCS/{deviceEUI}"); Assert.NotNull(pq); var payload = Payload.Parser.ParseFrom(pq.Payload); Assert.Equal(17, payload.Metrics.Count); }
public static DTOBuilding GetBuildingById(int id) { using (var context = GetNewContext()) { var list = new List <DTOBuilding>(); list = context.Buildings .AsNoTracking() .Where(x => x.IDBuilding == id) .Select(x => new DTOBuilding { Id = x.IDBuilding, Name = x.Name, Country = x.Country, Region = x.Region, City = x.City, Street = x.Street, House = x.House, Cinemas = x.ArtOrganizations .Where(org => org.OrganizationType == "Кинотеатр") .Select(c => new DTOArtOrganization { Id = c.IDOrganization, Name = c.Name, Rating = c.ComfortabilityRating, Website = c.Website, WorkHours = c.WorkHours }).ToList(), Restaurants = context.Restaurants.Select(r => new DTORestaurant { Id = r.IDOrganization, Name = r.Name, Rating = r.Rating, Website = r.Website, AverageCheck = r.AverageCheck, WorkHours = r.WorkHours, NumberOfEmptyTables = r.NumberOfEmptyTables }).ToList() }) .ToList(); if (list.Count == 0) { return(MockDataService.GetBuildingById()); } return(list.FirstOrDefault()); } }
static void Main(string[] args) { var cabid = Guid.Parse("ea1d410c-37d7-e611-9c39-f8cab83fa799"); var itemid = Guid.Parse("c621927c-39d7-e611-9c39-f8cab83fa799"); ILogger logger = new MockFileLogger(); IDataService svc = new MockDataService(logger); var cab = svc.GetCabinet(cabid); var user = svc.GetUserInfo("SomeUser"); PrintStat(cab); var billId = svc.GetAvailableItemLocker(cabid, user.UserId, itemid, "XXXXX-X"); var bill = svc.QueryBill(billId); var lockerid = bill.LockerId; PrintStat(cab); //open gate svc.RecordGatePropertyChange(cabid, lockerid, true); //take away item svc.RecordRfidPropertyChange(cabid, lockerid, string.Empty); //[optional] close gate svc.RecordGatePropertyChange(cabid, lockerid, false); Thread.Sleep(60000); var ret_lockerid = svc.GetAvailableEmptyLocker(cabid, user.UserId, itemid); //open gate svc.RecordGatePropertyChange(cabid, lockerid, true); //put back item svc.RecordRfidPropertyChange(cabid, lockerid, "return item A"); //close gate svc.RecordGatePropertyChange(cabid, lockerid, false); Console.Read(); }
public void Authorization_MockUser() { int count; CityDomainService cities = new CityDomainService(); DomainServiceDescription serviceDescription = DomainServiceDescription.GetDescription(typeof(CityDomainService)); DomainOperationEntry getZipsIfAuthenticated = serviceDescription.GetQueryMethod("GetZipsIfAuthenticated"); DomainOperationEntry getZipsIfInRole = serviceDescription.GetQueryMethod("GetZipsIfInRole"); // Validate a null principal is denied MockUser user = null; MockDataService dataService = new MockDataService(user); cities.Initialize(new DomainServiceContext(dataService, DomainOperationType.Query)); Exception expectedException = null; System.Collections.IEnumerable result; IEnumerable<ValidationResult> validationErrors = null; try { result = cities.Query(new QueryDescription(getZipsIfAuthenticated), out validationErrors, out count); } catch (UnauthorizedAccessException e) { expectedException = e; } Assert.IsNotNull(expectedException); Assert.IsNull(validationErrors); Assert.AreEqual("Access to operation 'GetZipsIfAuthenticated' was denied.", expectedException.Message, "Expected standard deny message for null principal"); // Validate a non-authenticated user is denied user = new MockUser("mathew"); dataService = new MockDataService(user); cities = new CityDomainService(); cities.Initialize(new DomainServiceContext(dataService, DomainOperationType.Query)); expectedException = null; validationErrors = null; try { user.IsAuthenticated = false; result = cities.Query(new QueryDescription(getZipsIfAuthenticated), out validationErrors, out count); } catch (UnauthorizedAccessException e) { expectedException = e; } Assert.IsNotNull(expectedException); Assert.IsNull(validationErrors); // we're authenticated, so this should succeed expectedException = null; user.IsAuthenticated = true; result = cities.Query(new QueryDescription(getZipsIfAuthenticated), out validationErrors, out count); Assert.IsNotNull(result); Assert.IsNull(validationErrors); // authenticated, but not in role, so we should fail cities = new CityDomainService(); expectedException = null; user = new MockUser("mathew", new string[] { "clerk" }); user.IsAuthenticated = true; dataService = new MockDataService(user); cities.Initialize(new DomainServiceContext(dataService, DomainOperationType.Query)); try { result = cities.Query(new QueryDescription(getZipsIfInRole), out validationErrors, out count); } catch (UnauthorizedAccessException e) { expectedException = e; } Assert.IsNotNull(expectedException); Assert.IsNull(validationErrors); // authenticated and in role, so we should succeed cities = new CityDomainService(); expectedException = null; user = new MockUser("mathew", new string[] { "manager" }); user.IsAuthenticated = true; dataService = new MockDataService(user); cities.Initialize(new DomainServiceContext(dataService, DomainOperationType.Query)); result = cities.Query(new QueryDescription(getZipsIfInRole), out validationErrors, out count); Assert.IsNotNull(result); Assert.IsNull(validationErrors); }
public void Authorization_Custom_Authorization_On_Query() { int count; CityDomainService cities = new CityDomainService(); DomainServiceDescription serviceDescription = DomainServiceDescription.GetDescription(typeof(CityDomainService)); DomainOperationEntry getZipsIfUser = serviceDescription.GetQueryMethod("GetZipsIfUser"); // The attribute permits only a user named mathew to access the query MockUser user = new MockUser("NotZipGuy"); MockDataService dataService = new MockDataService(user); cities.Initialize(new DomainServiceContext(dataService, DomainOperationType.Query)); // not authenticated should be denied cleanly because there is no user name Exception expectedException = null; System.Collections.IEnumerable result; IEnumerable<ValidationResult> validationErrors = null; try { user.IsAuthenticated = false; result = cities.Query(new QueryDescription(getZipsIfUser), out validationErrors, out count); } catch (UnauthorizedAccessException e) { expectedException = e; } Assert.IsNotNull(expectedException); Assert.AreEqual("Only one user is authorized for this query, and it isn't you.", expectedException.Message, "Expected this custom authorization deny message for non-authenticated user."); Assert.IsNull(validationErrors); // Authenticated, but still not the right user name -- should be denied cities = new CityDomainService(); expectedException = null; user = new MockUser("NotZipGuy", new string[] { "clerk" }); user.IsAuthenticated = true; dataService = new MockDataService(user); cities.Initialize(new DomainServiceContext(dataService, DomainOperationType.Query)); try { result = cities.Query(new QueryDescription(getZipsIfUser), out validationErrors, out count); } catch (UnauthorizedAccessException e) { expectedException = e; } Assert.IsNotNull(expectedException); Assert.AreEqual("Only one user is authorized for this query, and it isn't you.", expectedException.Message, "Expected this custom authorization deny message for authenticated user with wrong name."); Assert.IsNull(validationErrors); // authenticated and in with the right name -- should be allowed cities = new CityDomainService(); expectedException = null; user = new MockUser("ZipGuy"); user.IsAuthenticated = true; dataService = new MockDataService(user); cities.Initialize(new DomainServiceContext(dataService, DomainOperationType.Query)); result = cities.Query(new QueryDescription(getZipsIfUser), out validationErrors, out count); Assert.IsNotNull(result); Assert.IsNull(validationErrors); Assert.IsTrue(result.OfType<Zip>().Any(), "Expected non-zero number of zip codes returned"); }
public ServiceTest() { this._dataService = new MockDataService(); this._dataServiceWrapper = new MockDatabaseServiceWrapper(this._dataService); }