public void ItWorks() { Thingy thingy = new Thingy(); string result = thingy.DoTheThing(); Assert.That(string.Equals(result, DataTypeConverter.ParseHexBinary("3120322046697a7a20342042757a7a2046697a7a203720382046697a7a2042757a7a2031312046697a7a2031332031342046697a7a42757a7a2031362031372046697a7a2031392042757a7a2046697a7a2032322032332046697a7a2042757a7a2032362046697a7a2032382032392046697a7a42757a7a2033312033322046697a7a2033342042757a7a2046697a7a2033372033382046697a7a2042757a7a2034312046697a7a2034332034342046697a7a42757a7a2034362034372046697a7a2034392042757a7a2046697a7a2035322035332046697a7a2042757a7a2035362046697a7a2035382035392046697a7a42757a7a2036312036322046697a7a2036342042757a7a2046697a7a2036372036382046697a7a2042757a7a2037312046697a7a2037332037342046697a7a42757a7a2037362037372046697a7a2037392042757a7a2046697a7a2038322038332046697a7a2042757a7a2038362046697a7a2038382038392046697a7a42757a7a2039312039322046697a7a2039342042757a7a2046697a7a2039372039382046697a7a2042757a7a"))); }
static void Main() { //We've already seen constructur injection (my prefered, and the most common method) //Setter injection is the other alternative (we'll ignore interface injection because it's plain nasty!) var thingy = new Thingy { Dependency = new ThingyDependency() }; }
public void AutoForwardTest() { var stateMachine = new StateMachine <Thingy, AutoFallbackState, AutoFallbackEvent>(thingy => thingy.State , (thingy, updateState) => thingy.State = updateState); stateMachine .AddTriggerAction(AutoFallbackEvent.TurnOn, _ => _testOutputHelper.WriteLine("Firing 'On' trigger")) .AddTriggerAction(AutoFallbackEvent.TurnOnAF, _ => _testOutputHelper.WriteLine("Firing 'TurnOnAF' trigger")); stateMachine.OnTransition += (o, args) => _testOutputHelper.WriteLine($"Changed from {args.TransitionResult.PreviousState} to {args.TransitionResult.CurrentState} via {args.TransitionResult.LastTransitionName} transition"); stateMachine.ConfigureState(AutoFallbackState.Off) .AddTransition(AutoFallbackEvent.TurnOn, AutoFallbackState.On, name: "On") .AddTransition(AutoFallbackEvent.TurnOnAF, AutoFallbackState.On, name: "OnAF"); stateMachine.ConfigureState(AutoFallbackState.On) .AddTransition(AutoFallbackEvent.TurnOff, AutoFallbackState.Off) .AddAutoForwardTransition(AutoFallbackEvent.TurnOnAF, AutoFallbackState.End, _ => true, name: "AutoEnd"); var testThingy = new Thingy(); stateMachine.FireTrigger(testThingy, AutoFallbackEvent.TurnOn); _testOutputHelper.WriteLine("End simple On transition" + Environment.NewLine + Environment.NewLine); testThingy = new Thingy(); stateMachine.FireTrigger(testThingy, AutoFallbackEvent.TurnOnAF); _testOutputHelper.WriteLine("End OnAF transition" + Environment.NewLine + Environment.NewLine); }
public void AutoForwardTest() { var stateMachine = new StateMachine <Thingy, afState, afEvent>(thingy => thingy.State , (thingy, updateState) => thingy.State = updateState); stateMachine .RegisterOnTransitionedAction((thingy, result) => { Console.WriteLine($"Changed from {result.PreviousState} to {result.CurrentState} via {result.LastTransitionName} transition"); }) .AddTriggerAction(afEvent.TurnOn, _ => Console.WriteLine("Firing 'On' trigger")) .AddTriggerAction(afEvent.TurnOnAF, _ => Console.WriteLine("Firing 'TurnOnAF' trigger")); stateMachine.ConfigureState(afState.Off) .AddTransition(afEvent.TurnOn, afState.On, name: "On") .AddTransition(afEvent.TurnOnAF, afState.On, name: "OnAF"); stateMachine.ConfigureState(afState.On) .AddTransition(afEvent.TurnOff, afState.Off) .AddAutoForwardTransition(afEvent.TurnOnAF, afState.End, _ => true, name: "AutoEnd"); var testThingy = new Thingy(); stateMachine.FireTrigger(testThingy, afEvent.TurnOn); Console.WriteLine("End simple On transition" + Environment.NewLine + Environment.NewLine); testThingy = new Thingy(); stateMachine.FireTrigger(testThingy, afEvent.TurnOnAF); Console.WriteLine("End OnAF transition" + Environment.NewLine + Environment.NewLine); }
public void Load() { FileFuncs.LoadFileOpen(fname); BaseCommand bc = new BaseCommand(); //TheManager.TM.DestroyAll(); for (int i = TheManager.TM.Thingies.Count - 1; i >= 0; --i) { bc.AddAction(new CDelete(TheManager.TM.Thingies[i])); } for (int i = FileFuncs.GetArrSize() - 1; i >= 0; --i) { DataStruct d = FileFuncs.ExtractElement(i); //Debug.Log(d.ObjectType); Thingy thing = PoolQueue.PQ.RequestThing((TypeOfThingy)d.ObjectType); bc.AddAction(new CSpawn(thing)); bc.AddAction(new CMovement(thing, new Vector3(d.TransformData[0], d.TransformData[1], d.TransformData[2]))); bc.AddAction(new CRotate(thing, Quaternion.Euler(d.TransformData[3], d.TransformData[4], d.TransformData[5]))); bc.AddAction(new CScale(thing, new Vector3(d.TransformData[6], d.TransformData[7], d.TransformData[8]))); //thing.transform.position = new Vector3(d.TransformData[0], d.TransformData[1], d.TransformData[2]); //thing.transform.rotation = Quaternion.Euler(d.TransformData[3], d.TransformData[4], d.TransformData[5]); //thing.transform.localScale = new Vector3(d.TransformData[6], d.TransformData[7], d.TransformData[8]); } bc.Do(); FileFuncs.LoadFileClose(); }
public async Task FileCachingService_GetCachedFileAsync_FileDoesntExist_ShouldCallFunctionAndWriteContentsToDisk() { // arrange string actualFileContents = null; string expectedPath = Path.Combine(TempPath, CacheFilename); var objectToSerialize = new Thingy("FileDoesntExist"); _fileCachingSettingsProviderMock .Setup(m => m.GetFileCachingSettings()) .Returns(new FileCachingSettingsModel { TemporaryFolder = TempPath }); _fileServiceMock .Setup(m => m.FileExists(expectedPath)) .Returns(false); _fileServiceMock .Setup(m => m.WriteAllText(expectedPath, It.IsAny <string>())) .Callback((string passedPass, string passedFileContents) => { actualFileContents = passedFileContents; }); // act var result = await _service.GetCachedFileAsync(CacheFilename, async() => await Task.FromResult(objectToSerialize), null); // assert Assert.AreEqual(objectToSerialize, result); Assert.IsNotNull(actualFileContents); Assert.IsTrue(actualFileContents.Contains(objectToSerialize.Name)); }
public async Task FileCachingService_GetCachedFileAsync_FileDoesntExist_Exception_LastRetrySucceeds() { // arrange string expectedPath = Path.Combine(TempPath, CacheFilename); var objectToSerialize = new Thingy("FileDoesntExist"); _fileCachingSettingsProviderMock .Setup(m => m.GetFileCachingSettings()) .Returns(new FileCachingSettingsModel { TemporaryFolder = TempPath }); _fileServiceMock .Setup(m => m.FileExists(expectedPath)) .Returns(false); _fileServiceMock .SetupSequence(m => m.WriteAllText(expectedPath, It.IsAny <string>())) .Throws(new Exception()) .Throws(new Exception()) .Pass(); // act var result = await _service.GetCachedFileAsync(CacheFilename, async() => await Task.FromResult(objectToSerialize), null); // assert Assert.AreEqual(objectToSerialize, result); _asyncServiceMock.Verify(m => m.Sleep(1000), Times.Exactly(2)); }
CartItems GetCartItems() { CartItems results = new CartItems(); try { var userId = Request.Cookies["cart"].Value; if (string.IsNullOrEmpty(userId)) { return(results); } var cartsCollection = Database.GetCollection <UserCart>("Carts"); var cart = cartsCollection.Find(x => x.UserId == userId).FirstOrDefault(); if (cart == null) { return(results); } foreach (var itemId in cart.Items) { ObjectId obj = new MongoDB.Bson.ObjectId(itemId); // var results = _collection.Find(x => x.Name != "").ToList(); Thingy thing = _collection.Find(x => x.Id == obj).FirstOrDefault(); if (thing != null) { results.Add(thing); } } } catch { } results.Items.Sort((x, y) => string.Compare(x.Thing.Name, y.Thing.Name)); return(results); }
public async Task <IActionResult> Edit(int id, [Bind("ThingyId,Count,Text")] Thingy thingy) { if (id != thingy.ThingyId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(thingy); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ThingyExists(thingy.ThingyId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(thingy)); }
public ActionResult DeleteConfirmed(long id) { Thingy thingy = db.Things.Find(id); db.Things.Remove(thingy); db.SaveChanges(); return(RedirectToAction("Index")); }
public void SetEnableRotation(DirtyFlagController controller, EdittingMode prev, List <GameObject> setToActive, Thingy toBeEditted, MeshFilter[] thingyMeshes) { SetEdittingMode(controller, prev, setToActive); editee = toBeEditted; mf = thingyMeshes; backButton = dcf.modes.sRot.backButton; }
bool ButtonHasBeenClicked() { if (!Input.GetMouseButtonUp(TheManager.TM.LEFT_MOUSE)) { return(true); } if (ButtonBool.AnyButtonClicked) { if (buttons.place.ButtonIsClicked) { if (dcf.spawnThingy != null && dcf.mLoc.mouseHit) { BaseCommand create = new BaseCommand(); Thingy thing = PoolQueue.PQ.RequestThing(dcf.spawnThingy.tot); create.AddAction(new CSpawn(thing)); create.AddAction(new CMovement(thing, dcf.mLoc.gizmoPseudoPos)); create.Do(); GoBack(); return(false); } } if (buttons.delete.ButtonIsClicked) { if (editee.Deletable()) { BaseCommand destroy = new BaseCommand(); destroy.AddAction(new CDelete(editee)); destroy.Do(); GoBack(); return(false); } } if (buttons.EnterMove.ButtonIsClicked) { EnablePosition ep = gameObject.AddComponent <EnablePosition>(); DeactivateOnSwitch(); ep.SetEnablePosition(dcf, this, dcf.modes.sPos.activeOnSwitch, editee, mf); return(false); } if (buttons.EnterRot.ButtonIsClicked) { EnableRotation ep = gameObject.AddComponent <EnableRotation>(); DeactivateOnSwitch(); ep.SetEnableRotation(dcf, this, dcf.modes.sRot.activeOnSwitch, editee, mf); return(false); } return(false); } return(true); }
[Test][ExpectedException(typeof(VerifyException))] public void ExpectationWillFailIfValueDoesntMatchMockInstance() { DynamicMock m1 = new DynamicMock(typeof(Thingy)); Thingy thingy = (Thingy)m1.MockInstance; Mock m2 = new Mock("x"); m2.Expect("y", thingy); m2.Invoke("y", new object[] { "something else" }, new string[] { "System.String" }); }
// // GET: /Default1/Delete/5 public ActionResult Delete(long id = 0) { Thingy thingy = db.Things.Find(id); if (thingy == null) { return(HttpNotFound()); } return(View(thingy)); }
public void SetEnableTranslation(DirtyFlagController controller, EdittingMode prev, List <GameObject> setToActive, Thingy toBeEditted, MeshFilter[] thingyMeshes, Material flash) { SetEdittingMode(controller, prev, setToActive); editee = toBeEditted; mf = thingyMeshes; flashColor = flash; dcf.mLoc.isInTranslate = true; buttons = dcf.modes.trans.buttons; }
public ActionResult Edit(Thingy thingy) { if (ModelState.IsValid) { db.Entry(thingy).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(thingy)); }
public void SetEnableStartPos(DirtyFlagController controller, EdittingMode prev, List <GameObject> setToActive, Thingy toBeEditted) { SetEdittingMode(controller, prev, setToActive); startPos = toBeEditted.transform.localPosition; dist = Vector3.Dot(dcf.worldCam.transform.forward, (startPos - dcf.worldCam.transform.position)); finalPosition = startPos; editee = toBeEditted; }
static void Main(string[] args) { Thingy thingy = new Thingy(); Widget widget = new Widget(); thingy.Action(); widget.Action(); Console.Out.WriteLine("Press any key to quit."); Console.ReadKey(); }
[Test] public void MockInstanceCanBeUsedAsValueInAnExpectation() { DynamicMock mockThingy = new DynamicMock(typeof(Thingy)); Thingy thingy = (Thingy)mockThingy.MockInstance; Mock m2 = new Mock("x"); m2.Expect("y", thingy); m2.Invoke("y", new object[] { thingy }, new string[] { "NMock.DynamicMockTest.Thingy" }); m2.Verify(); }
public void ANullPropertyValueShouldNotSerializeAsAnEmptyElement() { var serializer = new XmlSerializer<Thingy>(x => x.Indent()); var blackHole = new Thingy { Uri = null }; var xml = serializer.Serialize(blackHole); Assert.That(xml, Is.Not.StringMatching(@"<Uri\s*/>")); }
public async Task <IActionResult> Create([Bind("ThingyId,Count,Text")] Thingy thingy) { if (ModelState.IsValid) { _context.Add(thingy); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(thingy)); }
public ActionResult Create(Thingy thingy) { if (ModelState.IsValid) { db.Things.Add(thingy); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(thingy)); }
public static void Main() { Thingy t = new Thingy(); // Note execution is deferred until enumeration (in this case Count()) var allData = t.GetData(); Console.WriteLine("All Data count: {0}", allData.Count()); // Select only valid records from data set (should be 2) var isValid = t.GetData(); isValid = isValid.Where(w => w.IsValid); Console.WriteLine("IsValid count: {0}", isValid.Count()); // select only records with an ID greater than 1 (should be 2) var gt1 = t.GetData(); gt1 = gt1.Where(w => w.Id > 1); Console.WriteLine("gt 1 count: {0}", gt1.Count()); // Here we're combining in a single statement, IsValid and gt 1 (should be 1) var isValidAndIdGt1 = t.GetData(); isValidAndIdGt1 = isValidAndIdGt1.Where(w => w.IsValid && w.Id > 1); Console.WriteLine("IsValid and gt 1 count: {0}", isValidAndIdGt1.Count()); // This is the same query as the one directly above, just broken up (could perhaps be some if logic in there to determine if to add the second Where // Note this is how you're doing it in your question (and it's perfectly valid (should be 1) var isValidAndIdGt1Appended = t.GetData(); isValidAndIdGt1Appended = isValidAndIdGt1Appended.Where(w => w.IsValid); isValidAndIdGt1Appended = isValidAndIdGt1Appended.Where(w => w.Id > 1); Console.WriteLine("IsValid and gt 1 count w/ appended where: {0}", isValidAndIdGt1Appended.Count()); // This is the same query as the one directly above, but note we are executing the query twice var isValidAndIdGt1AppendedTwice = t.GetData(); isValidAndIdGt1AppendedTwice = isValidAndIdGt1AppendedTwice.Where(w => w.IsValid); Console.WriteLine("IsValid and gt 1 count w/ appended where executing twice: {0}", isValidAndIdGt1AppendedTwice.Count()); // 2 results are valid isValidAndIdGt1AppendedTwice = isValidAndIdGt1AppendedTwice.Where(w => w.Id > 1); Console.WriteLine("IsValid and gt 1 count w/ appended where executing twice: {0}", isValidAndIdGt1AppendedTwice.Count()); // 1 result is both valid and id gt 1 // This is one of the things you were asking about - note that without assigning the additional Where criteria to the Iqueryable, you do not get the results of the where clause, but the original query - in this case there are no appended where conditions on the t.GetData() call, so you get the full result set. var notReallyValid = t.GetData(); notReallyValid.Where(w => w.Name == "this name definitly does not exist"); Console.WriteLine("where clause not correctly appended count: {0}", notReallyValid.Count()); // vs var validUse = t.GetData(); validUse = validUse.Where(w => w.Name == "this name definitly does not exist"); Console.WriteLine("valid use count: {0}", validUse.Count()); }
public void ANullPropertyValueShouldNotSerializeAsAnEmptyElement() { var serializer = new XmlSerializer <Thingy>(x => x.Indent()); var blackHole = new Thingy { Uri = null }; var xml = serializer.Serialize(blackHole); Assert.That(xml, Is.Not.StringMatching(@"<Uri\s*/>")); }
public Thingy CastIntoScene(Camera raycam) { Ray mouseray = raycam.ScreenPointToRay(Input.mousePosition); cam = raycam.transform; RaycastHit rch; Thingy targettedObject = null; mouseHit = false; wireFrame = false; for (int i = TheManager.TM.Thingies.Count - 1; i >= 0; --i) { MeshFilter[] m = TheManager.TM.Thingies[i].GetComponentsInChildren <MeshFilter>(); for (int j = m.Length - 1; j >= 0; --j) { MeshCollider MeCo = TheManager.TM.Thingies[i].gameObject.AddComponent <MeshCollider>(); MeCo.sharedMesh = m[j].sharedMesh; if (MeCo.Raycast(mouseray, out rch, 10000f)) { //Debug.Log(TheManager.TM.Thingies[i].name); if (targettedObject == null) { targettedObject = TheManager.TM.Thingies[i]; mouseDistance = rch.distance; gizmoPseudoPos = rch.point; gizmoPos = m[j].transform.position; gizmoRot = m[j].transform.rotation; gizmoScale = m[j].transform.localScale; me = m[j].sharedMesh; mouseHit = true; wireFrame = true; } else if (mouseDistance > rch.distance) { targettedObject = TheManager.TM.Thingies[i]; mouseDistance = rch.distance; gizmoPseudoPos = rch.point; gizmoPos = m[j].transform.position; gizmoRot = m[j].transform.rotation; gizmoScale = m[j].transform.localScale; me = m[j].sharedMesh; } } Destroy(MeCo); } } return(targettedObject); }
public Thingy GetThingyOfType(TypeOfThingy tot) { for (int i = 0; i < Controls.Count; i++) { Thingy thing = Controls[i].TryForType(tot); if (thing != null) { return(thing); } } return(null); }
public void SetEnableStartRot(DirtyFlagController controller, EdittingMode prev, List <GameObject> setToActive, Thingy toBeEditted) { SetEdittingMode(controller, prev, setToActive); startRot = toBeEditted.transform.localRotation; mPosInitial = Input.mousePosition; objectOnScreen = dcf.worldCam.WorldToScreenPoint(toBeEditted.transform.position); objectOnScreen.z = 0f; finalRotation = startRot; //Debug.Log(objectOnScreen); editee = toBeEditted; }
bool TranslationMode() { Thingy t = dcf.mLoc.CastIntoScene(dcf.worldCam); if (t != null) { EnableTranslation trans = gameObject.AddComponent <EnableTranslation>(); DeactivateOnSwitch(); trans.SetEnableTranslation(dcf, this, dcf.modes.trans.activeOnSwitch, t, t.GetComponentsInChildren <MeshFilter>(), dcf.modes.trans.flashColor); return(false); } return(true); }
public void VerifyThatAPropertyOfTypeTypeCanSuccessfullyRoundTrip(string uriString) { var serializer = new XmlSerializer<Thingy>(x => x.Indent()); var blackHole = new Thingy { Uri = new Uri(uriString) }; var xml = serializer.Serialize(blackHole); Console.WriteLine(xml); var roundTrip = serializer.Deserialize(xml); Assert.That(roundTrip.Uri, Is.EqualTo(blackHole.Uri)); }
bool TranslationMode() { Thingy t = dcf.mLoc.CastIntoScene(dcf.worldCam); if (t == null) { GoBack(); return(false); } mf = t.GetComponentsInChildren <MeshFilter>(); editee = t; return(true); }
public static void SpawnObject() { GameObject NewOBJ; List <string> AllFiles = new List <string>(Directory.GetFiles(Application.dataPath + "/prefabs/items/")); string Path; foreach (string Thingy in AllFiles) { Path = "Assets" + Thingy.Replace(Application.dataPath, "").Replace('\\', '/'); NewOBJ = (GameObject)AssetDatabase.LoadAssetAtPath(Path, typeof(GameObject)); PrefabUtility.InstantiatePrefab(NewOBJ); } }
Thingy RequestFromSlot(TypeOfThingy tot, int i) { for (int j = 0; j < IQS[i].things.Count; j++) { if (!IQS[i].things[j].gameObject.activeSelf) { IQS[i].things[j].PseudoAwake(); return(IQS[i].things[j]); } } Thingy thing = TheManager.TM.GetThingyOfType(IQS[i].ttype); return(thing); }
public void VerifyThatAPropertyOfTypeTypeCanSuccessfullyRoundTrip(string uriString) { var serializer = new XmlSerializer <Thingy>(x => x.Indent()); var blackHole = new Thingy { Uri = new Uri(uriString) }; var xml = serializer.Serialize(blackHole); Console.WriteLine(xml); var roundTrip = serializer.Deserialize(xml); Assert.That(roundTrip.Uri, Is.EqualTo(blackHole.Uri)); }
public MusicFolderTests() { _thingy = new Thingy(); }
private void HandleGotThingy(Thingy thingy) { if (thingy.isGood) { FSoundManager.PlaySound("get"); hudLayer.score += 1; maxThingies += 5; goodThingiesCount--; } else { gameOver = true; FSoundManager.PlaySound("lose"); FLabel score = new FLabel("BlairMdITC", hudLayer.score.ToString()); score.x = Futile.screen.halfWidth; score.y = Futile.screen.halfHeight + 75; score.scale = 0f; score.color = Color.black; Go.to(score, 0.5f, new TweenConfig().addTweenProperty(new FloatTweenProperty("scale", 1.0f, false)).setEaseType(EaseType.BackInOut)); AddChild(score); again = new FButton("button.png", "buttonOver.png", "spawn"); again.SignalRelease += HandleAgainSignalRelease; again.AddLabel("BlairMdITC", "Play Again", Color.black); again.label.scale = 0.3f; again.scale = 0f; again.x = Futile.screen.halfWidth; again.y = Futile.screen.halfHeight; Go.to(again, 0.5f, new TweenConfig().addTweenProperty(new FloatTweenProperty("scale", 1.0f, false)).setEaseType(EaseType.BackInOut)); AddChild(again); } thingies.Remove(thingy); thingy.Destroy(); }
private void AddNewThingy(bool withSound) { Thingy thingy; if (withSound) FSoundManager.PlaySound("spawn"); if (goodThingiesCount < maxGoodThingies) { thingy = new Thingy(true); goodThingiesCount++; } else { thingy = new Thingy(false); } thingy.x = Random.Range(thingy.GetContentRect().width / 2, Futile.screen.width - thingy.GetContentRect().width / 2); thingy.y = Random.Range(thingy.GetContentRect().height / 2, Futile.screen.height - thingy.GetContentRect().height / 2); thingyContainer.AddChild(thingy); thingies.Add(thingy); thingy.Inflate(); }