Ejemplo n.º 1
0
        public void ResolvedWithOkTypeAndErrType_UnwrapValue()
        {
            Resolved <bool, string> resolved = Resolved.Ok(true);
            var value = resolved.Unwrap();

            Assert.IsTrue(value);
        }
Ejemplo n.º 2
0
        public void ResolvedWithIntegerOk_UnwrapValue()
        {
            Resolved <int> resolved = Resolved.Ok(5);
            var            value    = resolved.Unwrap();

            Assert.AreEqual(5, value);
        }
    static Resolved GetOrAdd(FieldType fieldType)
    {
        return(cache.GetOrAdd(
                   fieldType.ResolvedType,
                   graphType =>
        {
            var resolved = new Resolved();
            if (graphType is ListGraphType listGraphType)
            {
                graphType = listGraphType.ResolvedType;
            }
            if (graphType is NonNullGraphType nonNullGraphType)
            {
                graphType = nonNullGraphType.ResolvedType;
            }

            if (graphType is IComplexGraphType complexType)
            {
                resolved.ComplexGraphType = complexType;
            }

            resolved.EntityType = ResolvedEntityType(graphType);
            return resolved;
        }));
    }
Ejemplo n.º 4
0
        public void DifferentTypeChainedResolvedOk_ResolvedValueIsTrue()
        {
            Resolved resolved = Resolved.Ok();

            var r = resolved
                    .Match <Resolved <int> >(
                Ok: () => Resolved.Ok(1),
                Err: (err) => Resolved.Err(err)
                )
                    .Match <Resolved>(
                Ok: (n) => Resolved.Ok(),
                Err: (err) => Resolved.Err(err)
                )
                    .Match <Resolved <bool> >(
                Ok: () => Resolved.Ok(true),
                Err: (err) => Resolved.Err(err)
                );

            Assert.IsTrue(r.IsOk);

            r.Match(
                Ok: (value) => { Assert.IsTrue(value); },
                Err: (err) => { Assert.Fail("Unexpected error occurred"); }
                );
        }
Ejemplo n.º 5
0
        public void ResolvedWithDefaultErr_ForwardErrThroughTheChain()
        {
            string   errorMessage = "Forwarded Err";
            Resolved resolved     = Resolved.ErrAsIEnumerable(new Exception(errorMessage));

            var result = resolved
                         .Match(
                Ok: () => Resolved.Ok(),
                Err: Behavior.Forward
                )
                         .Match(
                Ok: () => Resolved.Ok(),
                Err: Behavior.Forward
                )
                         .Match <int>(
                Ok: () => Resolved.Ok(1),
                Err: Behavior.Forward
                );

            Assert.AreEqual(typeof(Err), result.Value.GetType());

            var err = (Err)result.Value;

            Assert.AreEqual(err.Value.First().Message, errorMessage);
        }
Ejemplo n.º 6
0
        public void NestedResolved_ReturnsResolvedOkWithIntValue()
        {
            Resolved <int>             innerResolved = Resolved.Ok(1);
            Resolved <Resolved <int> > resolved      = Resolved.Ok(innerResolved);

            var result = resolved.Match <Resolved <int> >(
                Ok: (r) =>
            {
                var number = r.Match(
                    Ok: (n) => 1,
                    Err: (err) => 0
                    );

                return(Resolved.Ok(number));
            },
                Err: (err) => Resolved.Err(err)
                );

            Assert.IsTrue(result.IsOk);

            result.Match(
                Ok: (n) => Assert.AreEqual(1, n),
                Err: (err) => Assert.Fail("Unexpected error occurred")
                );
        }
        public IHttpActionResult PutResolved(int id, Resolved resolved)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != resolved.Id)
            {
                return(BadRequest());
            }

            db.Entry(resolved).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ResolvedExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 8
0
        public void SameTypeChainedResolvedOk_ReturnsLastNumberInTheChain()
        {
            Resolved <int> resolved = Resolved.Ok(0);

            var r = resolved
                    .Match <Resolved <int> >(
                Ok: (n) => Resolved.Ok(1),
                Err: (err) => Resolved.Err(err)
                )
                    .Match <Resolved <int> >(
                Ok: (n) => Resolved.Ok(2),
                Err: (err) => Resolved.Err(err)
                )
                    .Match <Resolved <int> >(
                Ok: (n) => Resolved.Ok(3),
                Err: (err) => Resolved.Err(err)
                );

            Assert.IsTrue(r.IsOk);

            r.Match(
                Ok: (n) => { Assert.AreEqual(3, n); },
                Err: (err) => { Assert.Fail("Unexpected error occurred"); }
                );
        }
Ejemplo n.º 9
0
        public void ResolvedWithDefaultErr_IsErrEqualsTrue()
        {
            IEnumerable <Exception> errors = new List <Exception>();
            Resolved resolved = Resolved.Err(errors);

            Assert.IsTrue(resolved.IsErr);
        }
Ejemplo n.º 10
0
        public void ResolvedWithStringErr_ForwardErrThroughTheChain()
        {
            string errorMessage = "Forwarded Err";
            Resolved <string, string> resolved = Resolved.Err(errorMessage);

            var result = resolved
                         .Match <int>(
                Ok: (innerValue) => Resolved.Ok(1),
                Err: Behavior.Forward
                )
                         .Match <bool>(
                Ok: (innerValue) => Resolved.Ok(true),
                Err: Behavior.Forward
                )
                         .Match <char>(
                Ok: (innerValue) => Resolved.Ok('\a'),
                Err: Behavior.Forward
                )
                         .Match(
                Ok: (innerValue) => Resolved.Ok('\b'),
                Err: Behavior.Forward
                );

            Assert.AreEqual(typeof(Err <string>), result.Value.GetType());

            var err = (Err <string>)result.Value;

            Assert.AreEqual(err.Value, errorMessage);
        }
Ejemplo n.º 11
0
        public override FullNamedExpression Resolve(ParseContext rc)
        {
            if (Resolved != null || Name == null)
            {
                return(Resolved);
            }

            if (rc == null)
            {
                return(null);
            }

            base.Resolve(rc);

            if (Resolved == null)
            {
                Name = null;
                return(null);
            }

            if (Resolved is TypeExpression)
            {
                Resolved = Resolved.ResolveAsBaseTerminal(rc, false);
            }

            return(Resolved);
        }
Ejemplo n.º 12
0
        public void ResolvedWithDefaultErr_IsOkEqualsFalse()
        {
            IEnumerable <Exception> err = new List <Exception>();
            Resolved resolved           = Resolved.Err(err);

            Assert.IsFalse(resolved.IsOk);
        }
Ejemplo n.º 13
0
        public void DifferentTypeChainedResolvedErr_ResolvedValueIsString()
        {
            IEnumerable <Exception> errors = new Exception[0];
            Resolved resolved = Resolved.Err(errors);

            var r = resolved
                    .Match <Resolved <bool> >(
                Ok: () => Resolved.Ok(true),
                Err: (err) => Resolved.Err(err)
                )
                    .Match <Resolved <int, string> >(
                Ok: (b) => Resolved.Ok(1),
                Err: (err) => Resolved.Err("Erro")
                );

            Assert.IsTrue(r.IsErr);

            r.Match(
                Ok: (n) => { Assert.Fail("Unexpected error occurred"); },
                Err: (err) =>
            {
                Assert.AreEqual(typeof(string), err.GetType());
                Assert.AreEqual("Erro", err);
            }
                );
        }
Ejemplo n.º 14
0
        public void ResolvedWithDefaultErr_UnwrapValueThrowsException()
        {
            Resolved <int> resolved = Resolved.ErrAsIEnumerable(new Exception());

            Assert.Throws(typeof(InvalidOperationException),
                          () => resolved.Unwrap());
        }
Ejemplo n.º 15
0
        public void Lookup()
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_Url.Replace("ssdp", "environment"));
                request.Accept = "application/json";

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    var serializer = new JsonSerializer();
                    using (var sr = new StreamReader(response.GetResponseStream()))
                        using (var jsonTextReader = new JsonTextReader(sr))
                        {
                            EnvironmentModel Model = (EnvironmentModel)serializer.Deserialize(jsonTextReader, typeof(EnvironmentModel));

                            string IPWithPort = m_IpAddress.Address + ((m_IpAddress.Port != 80) ? ":" + m_IpAddress.Port : "");

                            Resolved?.Invoke(this, new DataGridRow()
                            {
                                Name = Model.machineName, Url = "http://" + IPWithPort + "/", IpAddress = IPWithPort, Location = Model.location
                            });
                        }
                }
            }
            catch (WebException)
            {
                LookupLegacy();
            }
            catch (Exception)
            {
                Errored?.Invoke(this, m_Url);
            }
        }
Ejemplo n.º 16
0
        public void ResolvedWithBoolErr_UnwrapValueThrowsException()
        {
            Resolved <int, bool> resolved = Resolved.Err(true);

            Assert.Throws(typeof(InvalidOperationException),
                          () => resolved.Unwrap());
        }
Ejemplo n.º 17
0
        public override String ToString()
        {
            if (Protocol.Equals(TcpProtocol))
            {
                if (Resolved != null)
                {
                    return(Resolved.ToString());
                }
            }
            else if (Protocol.Equals(IpcProtocol))
            {
                if (Resolved != null)
                {
                    return(Resolved.ToString());
                }
            }
            else if (Protocol.Equals(PgmProtocol))
            {
                if (Resolved != null)
                {
                    return(Resolved.ToString());
                }
            }

            if (!string.IsNullOrEmpty(Protocol) && !string.IsNullOrEmpty(AddressString))
            {
                return(Protocol + "://" + AddressString);
            }

            return(null); //TODO: REVIEW - Although not explicitly prohibited, returning null from ToString seems sketchy; return string.Empty?
        }
Ejemplo n.º 18
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(New.GetHashCode() ^ Open.GetHashCode() ^ Resolved.GetHashCode() ^ OnHold.GetHashCode() ^ Invalid.GetHashCode() ^ Duplicate.GetHashCode() ^ Wontfix.GetHashCode());
     }
 }
Ejemplo n.º 19
0
        private void EnableButtons()
        {
            if (Module.InTheMiddleOfRebase())
            {
                if (Height < 200)
                {
                    Height = 500;
                }

                Branches.Enabled = false;
                Ok.Enabled       = false;
                chkStash.Enabled = false;

                AddFiles.Enabled  = true;
                Commit.Enabled    = true;
                Resolved.Enabled  = !Module.InTheMiddleOfConflictedMerge();
                Mergetool.Enabled = Module.InTheMiddleOfConflictedMerge();
                Skip.Enabled      = true;
                Abort.Enabled     = true;
            }
            else
            {
                Branches.Enabled  = true;
                Ok.Enabled        = true;
                AddFiles.Enabled  = false;
                Commit.Enabled    = false;
                Resolved.Enabled  = false;
                Mergetool.Enabled = false;
                Skip.Enabled      = false;
                Abort.Enabled     = false;
                chkStash.Enabled  = Module.IsDirtyDir();
            }

            SolveMergeconflicts.Visible = Module.InTheMiddleOfConflictedMerge();

            Resolved.Text            = _continueRebaseText.Text;
            Mergetool.Text           = _solveConflictsText.Text;
            Resolved.ForeColor       = SystemColors.ControlText;
            Mergetool.ForeColor      = SystemColors.ControlText;
            ContinuePanel.BackColor  = Color.Transparent;
            MergeToolPanel.BackColor = Color.Transparent;

            var highlightColor = Color.Yellow.AdaptBackColor();

            if (Module.InTheMiddleOfConflictedMerge())
            {
                AcceptButton = Mergetool;
                Mergetool.Focus();
                Mergetool.Text           = _solveConflictsText2.Text;
                MergeToolPanel.BackColor = highlightColor;
            }
            else if (Module.InTheMiddleOfRebase())
            {
                AcceptButton = Resolved;
                Resolved.Focus();
                Resolved.Text           = _continueRebaseText2.Text;
                ContinuePanel.BackColor = highlightColor;
            }
        }
Ejemplo n.º 20
0
 protected override void InnerExecute()
 {
     foreach (var slaveCommand in _slaveCommands)
     {
         slaveCommand.Execute(Resolved);
     }
     Resolved.Persist();
 }
Ejemplo n.º 21
0
        public ActionResult DeleteConfirmed(int id)
        {
            Resolved resolved = db.Resolveds.Find(id);

            db.Resolveds.Remove(resolved);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public void AddAsset(Hash128 guid, Hash128 targetHash, AssetObjectManifest manifest, AssetBundle assetBundle)
 {
     _Assets[guid] = new Resolved
     {
         AssetObjectManifest = manifest,
         AssetBundle         = assetBundle,
         TargetHash          = targetHash
     };
 }
Ejemplo n.º 23
0
 public ActionResult Edit([Bind(Include = "Id,DeviceId,SuspiciousActivites,_Date,TimeResolved,Verdict, StoreName, StoreLocation")] Resolved resolved)
 {
     if (ModelState.IsValid)
     {
         db.Entry(resolved).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(resolved));
 }
Ejemplo n.º 24
0
 public ActionResult Edit([Bind(Include = "Id,DeviceId,Department,ThreatLevel,TimeOccured,TimeResolved,Verdict")] Resolved resolved)
 {
     if (ModelState.IsValid)
     {
         db.Entry(resolved).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(resolved));
 }
Ejemplo n.º 25
0
        public ActionResult Create([Bind(Include = "Id,DeviceId,Department,ThreatLevel,TimeOccured,TimeResolved,Verdict")] Resolved resolved)
        {
            if (ModelState.IsValid)
            {
                db.Resolveds.Add(resolved);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(resolved));
        }
Ejemplo n.º 26
0
        private async void AddResolvedIncident(Resolved resolved_incident)
        {
            //var httpClient = new HttpClient();
            //var byteArray = Encoding.ASCII.GetBytes("TeamMeijer:Need Anything?");
            //var header = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
            //httpClient.DefaultRequestHeaders.Authorization = header;

            string json_object = JsonConvert.SerializeObject(resolved_incident);
            var    content     = new StringContent(json_object, Encoding.UTF8, "application/json");
            await App.httpClient.PostAsync("https://rsml.azurewebsites.net/api/Resolveds1", content);
        }
Ejemplo n.º 27
0
        public void ResolvedErrWithNullValue_ArgumentNullException()
        {
            Resolved resolved = Resolved.Err(null);

            Assert.Throws(
                typeof(ArgumentNullException),
                () => resolved.Match(
                    Ok: () => true,
                    Err: (err) => true
                    ));
        }
Ejemplo n.º 28
0
        public void ErrAsIEnumerable_ReturnsResolvedWithDefaultErr()
        {
            Resolved resolved = Resolved.ErrAsIEnumerable(new Exception());

            Assert.IsTrue(resolved.IsErr);

            resolved.Match(
                Ok: () => Assert.Fail("Unexpected error"),
                Err: (err) => Assert.IsTrue(err.GetType().GetInterfaces().Contains(typeof(IEnumerable <Exception>)))
                );
        }
Ejemplo n.º 29
0
        public ActionResult Create([Bind(Include = "Id,DeviceId,SuspiciousActivites,_Date,TimeResolved,Verdict, StoreName, StoreLocation")] Resolved resolved)
        {
            if (ModelState.IsValid)
            {
                db.Resolveds.Add(resolved);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(resolved));
        }
        public IHttpActionResult GetResolved(int id)
        {
            Resolved resolved = db.Resolveds.Find(id);

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

            return(Ok(resolved));
        }