Esempio n. 1
0
        public async void CanCreateNewNoodle()
        {
            DbContextOptions <NoodleContext> options = new DbContextOptionsBuilder <NoodleContext>()
                                                       .UseInMemoryDatabase("CanPostNewNoodle")
                                                       .Options;

            using (NoodleContext context = new NoodleContext(options))
            {
                //arrange
                Noodle noodle = new Noodle
                {
                    Name        = "Instant Noodle Shrimp",
                    BrandId     = 2,
                    Flavor      = "Tom Yum",
                    ImgUrl      = "https://www.bing.com",
                    Description = "much tasty"
                };

                //act
                await context.Noodles.AddAsync(noodle);

                await context.SaveChangesAsync();

                NoodleController nc = new NoodleController(context);
                var addedNoodle     = nc.Create(noodle);

                var results = context.Noodles.Where(x => x.Name == "Instant Noodle Shrimp");

                //assert
                Assert.Equal(1, results.Count());
            }
        }
Esempio n. 2
0
        public async void CanGetAllNoodle()
        {
            DbContextOptions <NoodleContext> options =
                new DbContextOptionsBuilder <NoodleContext>()
                .UseInMemoryDatabase("CanGetAllNoodles")
                .Options;

            using (NoodleContext context = new NoodleContext(options))
            {
                //arrange
                Noodle noodle1 = new Noodle();
                noodle1.Id   = 1;
                noodle1.Name = "Organic Ramen";
                Noodle noodle2 = new Noodle();
                noodle2.Id   = 2;
                noodle2.Name = "Shoyu Ramen";
                Noodle noodle3 = new Noodle();
                noodle3.Id   = 3;
                noodle3.Name = "Bestest Ramen";

                //act
                await context.Noodles.AddAsync(noodle1);

                await context.Noodles.AddAsync(noodle2);

                await context.Noodles.AddAsync(noodle3);

                await context.SaveChangesAsync();

                //assert
                Assert.Equal(3, context.Noodles.Count());
            }
        }
Esempio n. 3
0
        public async void CanUpdateNoodle()
        {
            DbContextOptions <NoodleContext> options = new DbContextOptionsBuilder <NoodleContext>()
                                                       .UseInMemoryDatabase("CanUpdateNoodle").Options;

            using (NoodleContext context = new NoodleContext(options))
            {
                //arrange
                Noodle noodle = new Noodle
                {
                    Flavor = "Tom Yum"
                };

                NoodleController nc = new NoodleController(context);

                //act
                await context.Noodles.AddAsync(noodle);

                await context.SaveChangesAsync();

                //the seeded data at id# 1 is Chapagetti, and this
                //test will override the flavor
                var updatedNoodle = nc.Update(1, noodle);

                //assert
                Assert.Equal("Tom Yum", noodle.Flavor);
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> Update(int id, [FromBody] Noodle noodle)
        {
            var dbNoodle = await _context.Noodles.FindAsync(id);

            if (dbNoodle == null)
            {
                return(NotFound());
            }

            //if (noodle.BrandId != null) dbNoodle.BrandId = noodle.BrandId;
            if (noodle.Flavor != null)
            {
                dbNoodle.Flavor = noodle.Flavor;
            }
            if (noodle.ImgUrl != null)
            {
                dbNoodle.ImgUrl = noodle.ImgUrl;
            }
            if (noodle.Name != null)
            {
                dbNoodle.Name = noodle.Name;
            }
            if (noodle.Description != null)
            {
                dbNoodle.Description = noodle.Description;
            }

            _context.Noodles.Update(dbNoodle);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([FromBody] Noodle noodle)
        {
            await _context.Noodles.AddAsync(noodle);

            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetNoodle", new { id = noodle.Id }, noodle));
        }
Esempio n. 6
0
        public void NoodleNameGetterTest()
        {
            Noodle noodle = new Noodle();

            noodle.Name   = "Cheese Ramen";
            noodle.Flavor = "Cheese";

            noodle.Name = "Extra spicy ramen";

            Assert.Equal("Extra spicy ramen", noodle.Name);
        }
Esempio n. 7
0
    public static void CalculateWeight(Dictionary <int, Noodle> Noodles, int Current)
    {
        Noodle CurrentNoodle = Noodles[Current];

        foreach (int UID in CurrentNoodle.Inputs)
        {
            Noodle Temp = Noodles[UID];
            if (Temp.Weight == 0)
            {
                CalculateWeight(Noodles, UID);
            }
            CurrentNoodle.Weight += Temp.Weight / Temp.Outputs.Count;
        }
    }
Esempio n. 8
0
        public static void Main(string[] args)
        {
            Pasta pasta = new Pasta();

            Noodle noodle = new Noodle();

            // print all steps of cooking paasta
            pasta.heatPan();
            pasta.addOil();
            pasta.addNoodle();

            //print all steps of cooking pasta
            pasta.heatPan();
            pasta.addOil();
            pasta.addNoodle();
        }
Esempio n. 9
0
        public BaseFood GenerateFood(string foodName)
        {
            BaseFood food = null;

            switch (foodName)
            {
            case "Noodle":
                food = new Noodle();
                break;

            case "Tomato":
                food = new Tomato();
                break;
            }
            return(food);
        }
Esempio n. 10
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.CompareTag("Noodle"))
     {
         Noodle current = collision.GetComponent <Noodle>();
         if (current.noodleType == type)
         {
             currentProgress++;
             LevelManager.instance.IncreaseCurrentCount();
             correctNoodle.Play();
             LevelManager.instance.AddScore(LevelManager.instance.correctNoodleValue);
         }
         else
         {
             LevelManager.instance.AddScore(LevelManager.instance.wrongNoodleValue);
             wrongNoodle.Play();
         }
     }
 }
Esempio n. 11
0
        /// <summary>
        /// method to retrieve current noodle data from api, updates server database
        /// </summary>
        /// <returns>view of current noodle list</returns>
        public async Task <IActionResult> ViewAllNoodles()
        {
            using (var client = new HttpClient())
            {
                // add the appropriate properties on top of the client base address.
                client.BaseAddress = new Uri("https://noodliciousapi.azurewebsites.net/");

                //the .Result is important for us to extract the result of the response from the call
                var response = client.GetAsync("/api/noodle").Result;

                if (response.EnsureSuccessStatusCode().IsSuccessStatusCode)
                {
                    var stringResult = await response.Content.ReadAsStringAsync();

                    var obj = JsonConvert.DeserializeObject <List <Noodle> >(stringResult);

                    foreach (var item in obj)
                    {
                        Noodle alreadyExists = await _context.Noodles.FirstOrDefaultAsync(x => x.Name == item.Name);

                        if (alreadyExists == null)
                        {
                            item.Id = null;
                            _context.Noodles.Add(item);
                        }
                        else
                        {
                            if (alreadyExists.Name != item.Name)
                            {
                                item.Id = null;
                                _context.Noodles.Add(item);
                            }
                        }
                    }

                    await _context.SaveChangesAsync();

                    return(View(obj));
                }
            }
            return(View());
        }
Esempio n. 12
0
        public async void CanDeleteNoodleByID()
        {
            DbContextOptions <NoodleContext> options =
                new DbContextOptionsBuilder <NoodleContext>()
                .UseInMemoryDatabase("CanDeleteNoodlesByID")
                .Options;

            using (NoodleContext context = new NoodleContext(options))
            {
                //arrange
                Noodle noodle1 = new Noodle();
                noodle1.Id   = 1;
                noodle1.Name = "Organic Ramen";
                Noodle noodle2 = new Noodle();
                noodle2.Id   = 2;
                noodle2.Name = "Shoyu Ramen";
                Noodle noodle3 = new Noodle();
                noodle3.Id   = 3;
                noodle3.Name = "Bestest Ramen";

                //act
                await context.Noodles.AddAsync(noodle1);

                await context.Noodles.AddAsync(noodle2);

                await context.Noodles.AddAsync(noodle3);

                await context.SaveChangesAsync();

                var findNoodle = context.Noodles.Find(1);

                NoodleController nc = new NoodleController(context);

                var deletedNoodle = nc.Delete(findNoodle.Id);

                //assert
                Assert.Equal(2, context.Noodles.Count());
            }
        }
Esempio n. 13
0
        public bool DoGraph(Rect graphRect)
        {
            Event   e = Event.current;
            Vector2 rawMousePosition = e.mousePosition;
            Vector2 mpos             = rawMousePosition - graphRect.position;

            // GUILayout.BeginHorizontal();
            //  GUILayout.Label(string.Join("\n", Selection.nodes.Select(x => string.Format("{0}: {1}", x.name, x.position.ToString())).ToArray()));
            //  GUILayout.FlexibleSpace();

            //  if(GUILayout.Button("serialize"))
            //  {
            //      graphSource = Serializer.Serialize(graph).ToString();
            //      Debug.Log( graphSource );
            //  }

            //  if(GUILayout.Button("de-serialize!"))
            //  {
            //      if(!string.IsNullOrEmpty(graphSource))
            //      {
            //          JsonObject o = (JsonObject) SimpleJson.SimpleJson.DeserializeObject(graphSource);
            //          graph = Serializer.Deserialize<Graph>(o);
            //      }
            //  }

            // GUILayout.EndHorizontal();

            if (e.type == EventType.MouseDown)
            {
            }
            else if (e.type == EventType.MouseDrag)
            {
                if (drag.type == DragType.None)
                {
                    if (e.button == MOUSE_MIDDLE || (e.button == MOUSE_LEFT && e.modifiers == EventModifiers.Alt))
                    {
                        drag.start          = rawMousePosition;
                        drag.type           = DragType.MoveCanvas;
                        drag.graphTransform = new GraphTransform(graph.transform);
                    }
                    else if (e.button == MOUSE_LEFT)
                    {
                        drag.start = mpos;
                        NodeHit hit;

                        if (GraphUtility.HitTest(graph, mpos, out hit))
                        {
                            if (hit.port != null)
                            {
                                drag.source   = new NodeAndPort(hit.node, hit.port);
                                drag.portType = hit.portType;
                                drag.type     = DragType.ConnectNoodle;
                            }
                            else
                            {
                                if (!Selection.nodes.Contains(hit.node))
                                {
                                    Selection.Add(hit.node, e.modifiers);
                                }
                                drag.type = DragType.MoveNodes;
                            }
                        }
                        else
                        {
                            Selection.Clear(e.modifiers);
                            drag.type = DragType.SelectionRect;
                        }
                    }
                }

                if (drag.type == DragType.MoveCanvas)
                {
                    graph.transform.offset = drag.graphTransform.offset + (rawMousePosition - drag.start);
                }
            }
            else if (e.type == EventType.MouseUp)
            {
                if (drag.type == DragType.MoveNodes)
                {
                    if (graphRect.Contains(mpos))
                    {
                        foreach (Node node in Selection.nodes)
                        {
                            node.position += (mpos - drag.start);
                        }
                    }
                }
                else if (drag.type == DragType.ConnectNoodle)
                {
                    NodeHit hit;

                    if (GraphUtility.HitTest(graph, mpos, out hit))
                    {
                        if (hit.port != null)
                        {
                            if (hit.portType != drag.portType)
                            {
                                if (drag.portType == PortType.Input)
                                {
                                    graph.noodles.Add(new Noodle(drag.source, hit));
                                }
                                else
                                {
                                    graph.noodles.Add(new Noodle(hit, drag.source));
                                }
                            }
                        }
                    }
                }
                else if (drag.type == DragType.None)
                {
                    if (e.button == MOUSE_LEFT)
                    {
                        NodeHit hit;

                        if (GraphUtility.HitTest(graph, mpos, out hit))
                        {
                            Selection.Add(hit.node, e.modifiers);
                        }
                        else
                        {
                            Selection.Clear(e.modifiers);
                        }
                    }
                }

                drag.Clear();
            }
            else if (e.type == EventType.Ignore)
            {
                drag.Clear();
            }
            else if (e.type == EventType.ContextClick)
            {
                OpenNodeMenu(mpos);
            }
            else if (e.type == EventType.KeyUp)
            {
                foreach (Shortcut shortcut in shortcuts)
                {
                    if (shortcut.Equals(e.keyCode, e.modifiers))
                    {
                        shortcut.command();
                    }
                }
            }

            graph.Draw(graphRect, Selection.nodes, drag.type == DragType.MoveNodes ? mpos - drag.start : Vector2.zero);

            if (drag.type == DragType.ConnectNoodle)
            {
                GUI.BeginGroup(graphRect);
                Noodle.Draw(drag.start, mpos);
                GUI.EndGroup();
            }

            if (e.type == EventType.MouseDown ||
                e.type == EventType.MouseUp ||
                e.type == EventType.MouseDrag ||
                e.type == EventType.KeyDown ||
                e.type == EventType.KeyUp ||
                e.type == EventType.ScrollWheel ||
                e.type == EventType.DragUpdated ||
                e.type == EventType.DragPerform ||
                e.type == EventType.DragExited)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 14
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Noodle") && NoodleCount < 6)
        {
            Rigidbody item = other.GetComponent <Rigidbody>();
            if (item == null || item.isKinematic)
            {
                return;
            }

            Noodle noodle = item.GetComponent <Noodle>();
            if (noodle == null || !noodle.IsCooked())
            {
                return;
            }

            ++_noodleCount;
            other.tag = "Untagged";
            other.gameObject.layer = 0;
            item.isKinematic       = true;
            other.enabled          = false;
            item.transform.parent  = transform;

            switch (NoodleCount)
            {
            case 1:
                item.transform.localEulerAngles = new Vector3(0, -180, 90);
                item.transform.localPosition    = new Vector3(-0.17f, 0.5f, 0.02f);
                break;

            case 2:
                item.transform.localEulerAngles = new Vector3(0, 0, 90);
                item.transform.localPosition    = new Vector3(0.18f, 0.51f, -0.05f);
                break;

            case 3:
                item.transform.localEulerAngles = new Vector3(0, 0, -79);
                item.transform.localPosition    = new Vector3(0.23f, 0.53f, 0.07f);
                break;

            case 4:
                item.transform.localEulerAngles = new Vector3(0, -90, -114);
                item.transform.localPosition    = new Vector3(0.14f, 0.57f, -0.4f);
                break;

            case 5:
                item.transform.localEulerAngles = new Vector3(0, 0, 79);
                item.transform.localPosition    = new Vector3(-0.24f, 0.5f, -0.13f);
                break;

            default:
                item.transform.localEulerAngles = new Vector3(0, -90, 114);
                item.transform.localPosition    = new Vector3(-0.08f, 0.58f, 0.35f);
                break;
            }
        }
        else if (other.CompareTag("RedPork") && _redPorkCount < 5)
        {
            Rigidbody item = other.GetComponent <Rigidbody>();
            if (item == null || item.isKinematic)
            {
                return;
            }

            ++_redPorkCount;
            other.tag = "Untagged";
            other.gameObject.layer = 0;
            item.isKinematic       = true;
            other.enabled          = false;
            item.transform.parent  = transform;

            switch (_redPorkCount)
            {
            case 1:
                item.transform.localEulerAngles = new Vector3(0, -180, 90);
                item.transform.localPosition    = new Vector3(-0.17f, 0.55f, 0.02f);
                break;

            case 2:
                item.transform.localEulerAngles = new Vector3(0, 0, 90);
                item.transform.localPosition    = new Vector3(0.18f, 0.56f, -0.05f);
                break;

            case 3:
                item.transform.localEulerAngles = new Vector3(0, 0, -79);
                item.transform.localPosition    = new Vector3(0.23f, 0.58f, 0.07f);
                break;

            case 4:
                item.transform.localEulerAngles = new Vector3(0, -90, -114);
                item.transform.localPosition    = new Vector3(0.14f, 0.62f, -0.4f);
                break;

            default:
                item.transform.localEulerAngles = new Vector3(0, -90, 114);
                item.transform.localPosition    = new Vector3(-0.08f, 0.63f, 0.35f);
                break;
            }
        }
        else if (other.CompareTag("OrangeFishBall") && !_hasOrangeFishBall)
        {
            Rigidbody item = other.GetComponent <Rigidbody>();
            if (item == null || item.isKinematic)
            {
                return;
            }

            _hasOrangeFishBall              = true;
            other.tag                       = "Untagged";
            other.gameObject.layer          = 0;
            item.isKinematic                = true;
            other.enabled                   = false;
            item.transform.parent           = transform;
            item.transform.localEulerAngles = new Vector3(90, 0, 0);
            item.transform.localPosition    = new Vector3(0f, 0.68f, 0f);
        }
        else if (other.CompareTag("Soup") && !_hasSoup)
        {
            other.GetComponent <Scoop>().Pour();

            _hasSoup = true;
            soup.SetActive(true);
        }
    }//OnTriggerEnter
Esempio n. 15
0
    static void Main(string[] args)
    {
        int N = Convert.ToInt32(Console.ReadLine().ToString());
        Dictionary <int, Noodle> Noodles = new Dictionary <int, Noodle>();

        for (int i = 1; i <= N; i++)
        {
            Noodles.Add(i, new Noodle());
        }

        for (int i = 0; i < (N - 1); i++)
        {
            string   Line  = Console.ReadLine();
            string[] LineA = Line.Split(' ');

            int NoodleID  = Convert.ToInt32(LineA[0]);
            int NoodleOut = Convert.ToInt32(LineA[1]);

            Noodle CurrentNoodle = Noodles[NoodleID];
            CurrentNoodle.Outputs.Add(NoodleOut);

            CurrentNoodle = Noodles[NoodleOut];
            CurrentNoodle.Inputs.Add(NoodleID);
        }

        for (int i = 1; i <= N; i++)
        {
            Noodle CurrentNoodle = Noodles[i];
            if (CurrentNoodle.Inputs.Count == 0)
            {
                CurrentNoodle.Weight = 1;
            }
        }

        for (int i = 1; i <= N; i++)
        {
            Noodle CurrentNoodle = Noodles[i];
            if (CurrentNoodle.Outputs.Count == 0)
            {
                CalculateWeight(Noodles, i);
            }
        }

        int Buyuk = Noodles[1].Weight;

        for (int i = 1; i <= N; i++)
        {
            Noodle CurrentNoodle = Noodles[i];
            if (CurrentNoodle.Weight > Buyuk)
            {
                Buyuk = CurrentNoodle.Weight;
            }
        }

        for (int i = 1; i <= N; i++)
        {
            Noodle CurrentNoodle = Noodles[i];
            if (CurrentNoodle.Weight == Buyuk)
            {
                Console.WriteLine("{0}", i, Environment.NewLine);
            }
        }
        Console.ReadLine();
    }