public void CannotDeserializeWithBlankName() { string contactsJson = @"[{""name"":""""}]"; this.Deserializer = new Shred30ContactsDeserializer(contactsJson); this.Deserializer.Deserialize(); }
public void CanDeserializeSameSideVariant() { string contactsJson = @"[{""name"":""mirage"",""sameside"":true}]"; this.Deserializer = new Shred30ContactsDeserializer(contactsJson); IEnumerable <IShred30Contact> shred30Contacts = this.Deserializer.Deserialize(); Assert.AreEqual(1, shred30Contacts.Count()); Assert.AreEqual("mirage", shred30Contacts.First().Name); Assert.IsTrue(shred30Contacts.First().IsSameSideVariant); }
public void CanDeserializeContact() { string contactsJson = @"[{""name"":""ripwalk""}]"; this.Deserializer = new Shred30ContactsDeserializer(contactsJson); IEnumerable <IShred30Contact> shred30Contacts = this.Deserializer.Deserialize(); Assert.AreEqual(1, shred30Contacts.Count()); Assert.AreEqual("ripwalk", shred30Contacts.First().Name); Assert.AreEqual(OrdinalSideType.None, shred30Contacts.First().StartSide); }
public IHttpActionResult Index(string shred30, string options = null) { try { Shred30Options shred30Options = this.GetShred30Options(options); Shred30ContactsDeserializer deserializer = new Shred30ContactsDeserializer(shred30); IEnumerable <IShred30Contact> shred30Contacts = deserializer.Deserialize(); IShred30ScoreCalculator scoreCalculator = Shred30ScoreCalculatorFactory.GetScoreCalculator(shred30Options, shred30Contacts); Shred30ScoreResponse scoreResponse = new Shred30ScoreResponse { Shred30String = shred30Contacts.GetCollection().Format(), Score = scoreCalculator.CalculateScore(), ScoreComponents = scoreCalculator.GetScoreComponents(), ContactExplanations = scoreCalculator.GetContactExplanations(), Shred30Options = shred30Options }; return(Ok(scoreResponse)); } catch (JsonException jsonException) { return(InternalServerError(jsonException)); } catch (DeserializationException deserializationException) { return(Content(HttpStatusCode.PreconditionFailed, deserializationException)); } catch (TrickNotFoundException trickNotFoundException) { return(Content(HttpStatusCode.NotFound, trickNotFoundException.Message)); } catch (NotAllTricksSpecifySidesException notAllTricksSpecifySideException) { return(Content(HttpStatusCode.PreconditionFailed, notAllTricksSpecifySideException.Message)); } catch (SurfacesDoNotLineUpException surfacesDoNotLineUpException) { return(Content(HttpStatusCode.PreconditionFailed, surfacesDoNotLineUpException.Message)); } catch (TrickAfterDropDoesNotSpecifySideException trickAfterDropDoesNotSpecifySideException) { return(Content(HttpStatusCode.PreconditionFailed, trickAfterDropDoesNotSpecifySideException)); } catch (Exception exception) { return(InternalServerError(exception)); } }
public void CanDeserializeMultipleContacts() { string contactsJson = @"[{""name"":""blurry whirl"",""side"":""left""},{""name"":""blur""},{""name"":""dimwalk""}]"; this.Deserializer = new Shred30ContactsDeserializer(contactsJson); List <IShred30Contact> shred30Contacts = this.Deserializer.Deserialize().ToList(); Assert.AreEqual(3, shred30Contacts.Count()); Assert.AreEqual("blurry whirl", shred30Contacts[0].Name); Assert.AreEqual(OrdinalSideType.Left, shred30Contacts[0].StartSide); Assert.AreEqual("blur", shred30Contacts[1].Name); Assert.AreEqual("dimwalk", shred30Contacts[2].Name); }