public async Task PostCheckAvailability_ShouldBeAvailable() { // Arrange var context = new TestBookStoreAPIContext(); var testBook = DemoData.GetDemoBook(); context.Books.Add(testBook); var testBookDTO = DemoData.GetDTOfromBook(testBook); var cartItem = new CartItem { Book = testBookDTO, Quantity = 1 }; var cart = new Cart() { CartItems = new List <CartItem> { cartItem } }; // Act var controller = new BooksController(context); var result = await controller.PostAvailability(cart) as IHttpActionResult; var contentResult = result as OkNegotiatedContentResult <ApiResponse>; var availableBooks = contentResult.Content.Data as IEnumerable <IBookDTO>; // Assert Assert.IsNotNull(result); Assert.IsTrue(!contentResult.Content.Error); Assert.AreEqual("all available", contentResult.Content.Message); Assert.AreEqual(testBookDTO, availableBooks.ElementAt(0)); }
public static void Main(string[] args) { /* Start DB Initialization on startup */ var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <DBContext>(); var uManager = services.GetRequiredService <UserManager <Client> >(); var rManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var demoData = new DemoData(context, uManager, rManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); Console.WriteLine("An error occurred while seeding the database."); } } host.Run(); /* End DB Initialization on startup */ //Comment-ed out for the DB initialization on startup //If no DB init needed, delete the code of the init and uncomment this line! //BuildWebHost(args).Run(); }
public void OnKeyboarddata(SocketIOEvent e) { DemoData ch = JsonUtility.FromJson <DemoData>(e.data.ToString()); SensorData = ch.SensorData.ToString(); Device = ch.id.ToString(); }
private void initialize() { id = "sprink" + new Random().Next().ToString(); location = "Patient/" + id; CreateDate = DateTimeOffset.Now; Patient patient = DemoData.GetDemoPatient(); ResourceEntry <Patient> entry; entry = client.Create <Patient>(patient, id, null, true); Versions.Add(entry.SelfLink); entry.Resource.Telecom.Add(new Contact() { System = Contact.ContactSystem.Email, Value = "*****@*****.**" }); entry = client.Update <Patient>(entry, refresh: true); Versions.Add(entry.SelfLink); entry = client.Update <Patient>(entry, refresh: true); Versions.Add(entry.SelfLink); client.Delete(location); }
private void FillinList_Clicked(object sender, RoutedEventArgs e) { DemoData data = new DemoData { Date = DateTime.Now.Date, Name = "Test" }; try { var proxy = GetProxy <IDemo>(); var List = proxy.Update(data, (int)setValue); foreach (var item in List) { DataList.Items.Add(item); } } catch (Exception exception) { MessageBox.Show(exception.Message, "Client Proxy Error:", MessageBoxButton.OK); } finally { var channelProxy = (IChannel)DemoProxy; if (channelProxy != null && channelProxy.State == CommunicationState.Opened) { channelProxy.Close(); } } }
private IEnumerator WaitToGetCommentByIndex(int commentIndex) { UnityWebRequest www = UnityWebRequest.Get(SERVER_URL); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { string responseText = www.downloadHandler.text; DemoData demoData = JsonConvert.DeserializeObject <DemoData>(responseText); if (commentIndex < demoData.comments.Count) { Comment currentComment = demoData.comments[commentIndex]; UICommunication.instance.SetCommentsOutput("Comment ID: " + currentComment.id + " Post ID: " + currentComment.postId + " Body: " + currentComment.body); } else { UICommunication.instance.SetCommentsOutput("Out Of Range"); } } }
public IActionResult Get(string request) { if (request == "CreateDemoData") { DemoData demo = new DemoData(); demo.CreateDemoData(db); return(Ok("Success")); } if (request == "TodaysMenu") { var todaysFood = db.Orders.Include("Menu").FirstOrDefault(o => o.Date == DateTime.Today); if (todaysFood != null) { var m = todaysFood.Menu; var menuToSend = new Menu { Id = m.Id, Name = m.Name, Description = m.Description }; return(Ok(menuToSend)); } else { return(Ok("Order is not created yet!")); } } return(Ok("You didn't request anything")); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationDbContext context, RoleManager <EmployeeRole> roleManager, UserManager <Employee> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); DemoData.Initialize(context, userManager, roleManager).Wait(); }
public async Task PostOrder_ShouldReturnError() { // Arrange var context = new TestBookStoreAPIContext(); var testBook = DemoData.GetDemoBook(); context.Books.Add(testBook); var cart = new Cart { //this item is out of stock CartItems = new List <CartItem> { new CartItem(DemoData.GetDTOfromBook(testBook), 5) } }; // Act var controller = new OrdersController(context); var result = await controller.PostOrder(cart) as IHttpActionResult; var contentResult = result as OkNegotiatedContentResult <ApiResponse>; // Assert Assert.IsNotNull(result); Assert.IsTrue(contentResult.Content.Error); }
public async Task GetOrder_ShouldReturnOrderDetails() { // Arrange var context = new TestBookStoreAPIContext(); var order = DemoData.GetDemoOrder(); context.Orders.Add(order); OrderItem orderItem = new OrderItem { Id = Util.Util.GetNewId(), OrderId = order.Id, BookId = "xta", SellingPrice = 499, Quantity = 1, ShippingStatus = 0, CreatedAt = new System.DateTime() }; context.OrderItems.Add(orderItem); // Act var controller = new OrdersController(context); var result = await controller.GetOrder("XyZ") as IHttpActionResult; var contentResult = result as OkNegotiatedContentResult <ApiResponse>; var orderDetails = contentResult.Content.Data as OrderDetailsDTO; // Assert Assert.IsNotNull(result); Assert.IsTrue(!contentResult.Content.Error); Assert.AreEqual("XyZ", orderDetails.Id); Assert.AreEqual(499, orderDetails.TotalAmount); }
public override global::System.Data.DataSet Clone() { DemoData cln = ((DemoData)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return(cln); }
public ActionResult DeleteConfirmed(int id) { DemoData demodata = db.DemoData.Find(id); db.DemoData.Remove(demodata); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Demo public ActionResult Index() { DemoData data = new DemoData(); data.ApplicationName = WebConfigurationManager.AppSettings["ApplicationDemoName"]; return(View(data)); }
private void NewGame() { // TODO: Game init logic here var gameState = DemoData.GenerateGameState(); this.WindowManager.ShowMainWindow(gameState); this.CloseAction?.Invoke(); }
public Player CreatePlayer(PlayerInputTest input) { int playerId = DemoData.GetNewPlayerId(); Player player = new Player(playerId, input.FirstName, input.LastName); DemoData.AddPlayer(player); return(player); }
public ActionResult Edit(DemoData demodata) { if (ModelState.IsValid) { db.Entry(demodata).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(demodata)); }
// // GET: /DemoData/Delete/5 public ActionResult Delete(int id = 0) { DemoData demodata = db.DemoData.Find(id); if (demodata == null) { return(HttpNotFound()); } return(View(demodata)); }
static void InitializeDb(IServiceProvider services) { var db = services.GetRequiredService <IAppDbContext>(); if (db.Database.IsSqlite()) { Log.Information("No Postgres connection string provided, using Sqlite database provider"); } else { Log.Information("Using Npgsql database provider"); } if (!db.Database.CanConnect() && !db.Database.GetMigrations().Any()) { db.Database.EnsureCreated(); } else if (db.Database.GetMigrations().Any()) { db.Database.Migrate(); } if (db.Contacts.Any()) { return; } Log.Information("Seeding database"); var rand = new Random(); var numbers = DemoData.GetNumbers(); var contacts = DemoData.GetContacts(); foreach (var contact in contacts) { contact.PhoneNumbers = new List <PhoneNumber> { new PhoneNumber { Number = numbers[rand.Next(0, 999)] }, new PhoneNumber { Number = numbers[rand.Next(0, 999)] }, new PhoneNumber { Number = numbers[rand.Next(0, 999)] }, new PhoneNumber { Number = numbers[rand.Next(0, 999)] }, }; db.Contacts.Add(contact); } db.SaveChanges(); Log.Debug("Database seeding complete"); }
public ActionResult Create(DemoData demodata) { if (ModelState.IsValid) { db.DemoData.Add(demodata); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(demodata)); }
public static void Dump(Stream file, string directory, int fileNumber) { uint structureCount = file.ReadUInt(); uint startOfIndexes = file.ReadUInt(); using (var outFile = new FileStream(Path.Combine(directory, $"{fileNumber}_Demos.csv"), FileMode.Create, FileAccess.Write)) { using (TextWriter output = new StreamWriter(outFile, Encoding.UTF8)) { using (var csv = new CsvWriter(output)) { csv.Configuration.QuoteAllFields = true; csv.Configuration.RegisterClassMap <DemoCSVMap>(); csv.WriteHeader <DemoData>(); csv.NextRecord(); for (int i = 0; i < structureCount; i++) { file.Position = startOfIndexes + (i * 4); uint structurePos = file.ReadUInt(); uint nextStructurePos; if (i + 1 < structureCount) { nextStructurePos = file.ReadUInt(); } else { nextStructurePos = (uint)file.Length; } uint structureSize = nextStructurePos - structurePos; file.Position = structurePos; file.ReadUInt(); // always 0x14 var data = new DemoData(); uint secondStringOffset = file.ReadUInt(); file.ReadUInt(); // end of struct offset - ignore it data.Unknown = file.ReadUInt(); data.IsLocked = file.ReadUInt(); data.Filename = file.ReadCharacters(); file.Position = structurePos + secondStringOffset; data.Course = file.ReadCharacters(); csv.WriteRecord(data); csv.NextRecord(); } } } } }
public void ValidateCreateResource() { Patient patient = DemoData.GetDemoPatient(); OperationOutcome oo; if (!client.TryValidateCreate(patient, out oo, null)) { TestResult.Fail("Validation incorrectly reported failure."); } }
public MainWindowViewModel() { if (this.IsInDesignMode) { this.GameState = DemoData.GenerateGameState(); Messenger.Default.Send(new GameStateLoadedMessage(this.GameState)); var selectedPlanet = this.GameState.Galaxy.Planets.Find(p => p.X <= 200 && p.Y <= 200); Messenger.Default.Send(new PlanetSelectedMessage(selectedPlanet)); } }
private List <Penalty> ResolvePenalties(Player p) { List <Penalty> output = new List <Penalty>(); foreach (int id in p.Penalties) { output.Add(DemoData.GetPenaltyById(id)); } return(output); }
public Penalty GetPenalty(int id) { foreach (var penalty in DemoData.GetPenalties()) { if (penalty.Id == id) { return(penalty); } } return(null); }
public void DemoMethodObject(DemoData data) { this._logger.LogInformation("Got object!"); this._logger.LogInformation(data?.GetType().FullName ?? "<NULL>"); this._objectHandle.Dispose(); if (data == null) { return; } this.Handle(data); }
public Player GetPlayer(int id) { foreach (var player in DemoData.GetPlayers()) { if (player.Id == id) { return(player); } } return(null); }
public async Task <Player> AssignPenaltyToPlayer(int playerId, int penaltyId, [Service] ITopicEventSender eventSender) { Player p = DemoData.AssignPenalty(penaltyId, playerId); if (p == null) { throw new Exception("PlayerNotFound"); } await eventSender.SendAsync("PenaltyAssigned", p); return(p); }
public void ValidateUpdateResource() { Patient patient = DemoData.GetDemoPatient(); ResourceEntry <Patient> result = client.Create <Patient>(patient); OperationOutcome oo; if (!client.TryValidateUpdate(result, out oo)) { TestResult.Fail("Validation incorrectly reported failure."); } }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { DemoData ds = new DemoData(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
public void UpdatePlayer(Data.PlayerInfo player, DemoData demo) { var isSpectator = player.State.Team <= DemoInfo.Team.Spectate; if (isSpectator) { return; } var renderInfo = GetOrCreateRenderInfo(player.EntityID); var playerPos = demo.WorldSpaceToMinimapSpace(new System.Windows.Vector(player.Position.PositionX, player.Position.PositionY)); var selected = SelectedPlayers.Contains(player.EntityID); var team = player.State.Team; var fillColor = GetFillColor(selected, team); var strokeColor = GetStrokeColor(selected, team); if (player.State.IsAlive) { renderInfo.PlayerPos.Visibility = Visibility.Visible; renderInfo.PlayerSight.Visibility = Visibility.Visible; renderInfo.DeathPos.Visibility = Visibility.Hidden; renderInfo.PlayerPos.Fill = fillColor; renderInfo.PlayerPos.Stroke = strokeColor; Canvas.SetLeft(renderInfo.PlayerPos, playerPos.X - 15 / 2); Canvas.SetTop(renderInfo.PlayerPos, playerPos.Y - 15 / 2); var left = playerPos + CreateVectorFromRotation(128, player.Position.ViewDirectionX - 45f); var right = playerPos + CreateVectorFromRotation(128, player.Position.ViewDirectionX + 45f); var center = (left + right) / 2; renderInfo.playerSightBrush.StartPoint = new Point(playerPos.X, playerPos.Y); renderInfo.playerSightBrush.EndPoint = new Point(center.X, center.Y); renderInfo.PlayerSight.Points[0] = new Point(playerPos.X, playerPos.Y); renderInfo.PlayerSight.Points[1] = new Point(left.X, left.Y); renderInfo.PlayerSight.Points[2] = new Point(right.X, right.Y); } else { renderInfo.PlayerPos.Visibility = Visibility.Hidden; renderInfo.PlayerSight.Visibility = Visibility.Hidden; renderInfo.DeathPos.Visibility = Visibility.Visible; renderInfo.DeathPos.Fill = fillColor; renderInfo.DeathPos.Stroke = strokeColor; Canvas.SetLeft(renderInfo.DeathPos, playerPos.X); Canvas.SetTop(renderInfo.DeathPos, playerPos.Y); } }
public void StringFormatAndConcat() { var data = new DemoData() { Id = 100, Name = "David Smith" }; // string.Format var message = string.Format("Id is {0} and Name is '{1}'", data.Id, data.Name); Assert.AreEqual<string>("Id is 100 and Name is 'David Smith'", message); // concat string message = "Id is " + data.Id + " and Name is '" + data.Name + "'"; Assert.AreEqual<string>("Id is 100 and Name is 'David Smith'", message); }
public void InterpolationWithNameOf() { var data = new DemoData() { Id = 100, Name = "David Smith" }; var message = $"{nameof(data.Id)} is {data.Id} and {nameof(data.Name)} is '{data.Name}'"; Assert.AreEqual<string>("Id is 100 and Name is 'David Smith'", message); }
public void InterpolationWithFormatSpecifier() { var data = new DemoData() { Id = 100, Name = "David Smith", Birthdate = new DateTime(1970, 2, 25)}; var message = $"Name is '{data.Name}' and Birthday is {data.Birthdate:M}"; Assert.AreEqual<string>("Name is 'David Smith' and Birthday is February 25", message); }
public void SimpleInterpolation() { var data = new DemoData() { Id = 100, Name = "David Smith" }; var message = $"Id is {data.Id} and Name is '{data.Name}'"; Assert.AreEqual<string>("Id is 100 and Name is 'David Smith'", message); }