public void Adding_an_attendee() { var sut = new Training(); sut.RegisterAttendee("a", "ea"); Equalidator.AreEqual(new[]{new Attendee{Name = "a", Email = "ea"}}, sut.Attendees); Assert.Throws<InvalidOperationException>(() => sut.RegisterAttendee("a", "ea")); }
public void Register_attendee(Training training, string name, string email, Action onSuccess, Action<string> onError) { Attendee a; if (training.TryGetAttendeeByEmail(email, out a)) onError(string.Format("Email '{0}' has already been registered.", email)); else { training.RegisterAttendee(name, email); onSuccess(); } }
public void Retrieving_an_attendee() { var sut = new Training(); sut.RegisterAttendee("a", "ea"); Attendee a; Assert.IsTrue(sut.TryGetAttendeeByEmail("ea", out a)); Assert.AreEqual("a", a.Name); Assert.IsFalse(sut.TryGetAttendeeByEmail("x", out a)); }
public void Note_feedback(Training training, string email, int score, string suggestions, Action onSuccess, Action<string> onError) { Attendee a; if (training.TryGetAttendeeByEmail(email, out a)) { a.Feedback.Score = score; a.Feedback.Suggestions = suggestions; onSuccess(); } else onError(string.Format("Attendee with email '{0}' hasnĀ“t been registered for training '{1}'.", email, training.Matchcode)); }
public void UpdateTraining(Training training, Action onSucces, Action<Exception> onFailure) { if (training.Id == null) throw new InvalidOperationException("Cannot update training which has not been created! Missing id. Matchcode: " + training.Matchcode); try { var doc = training.ToBsonDocument(); var result = _mdbCol.Update(Query.EQ("_id", training.Id), Update.Replace(doc), UpdateFlags.None); if (result.UpdatedExisting) onSucces(); else throw new InvalidOperationException("Could not find training to update! Matchcode: " + training.Matchcode); } catch (Exception ex) { onFailure(ex); } }
public static Training ToTraining(this BsonDocument doc) { var training = new Training { Id = doc["_id"].AsString, Matchcode = doc["Matchcode"].AsString, TrainerMatchcode = doc["TrainerMatchcode"].AsString, Attendees = doc["Attendees"].AsBsonArray .Select(a => new Attendee { Name = a["Name"].AsString, Email = a["Email"].AsString, Feedback = new Feedback { Score = a["Feedback"]["Score"].AsInt32, Suggestions = a["Feedback"]["Suggestions"].AsString, } } ) .ToArray() }; return training; }
public void CreateTraining(string matchcode, string trainerMatchcode, Action<Training> onSuccess, Action<Exception> onFailure) { var training = new Training {Matchcode = matchcode, TrainerMatchcode = trainerMatchcode}; var doc = training.ToBsonDocument(); try { _mdbCol.Insert(doc); training.Id = doc["_id"].AsString; onSuccess(training); } catch (Exception ex) { onFailure(ex); } }
public double Average_scores(Training training) { var scores = training.Attendees.Where(a => a.Feedback.Score > 0) .Select(a => a.Feedback.Score).ToArray(); return scores.Length > 0 ? scores.Average() : 0.0; }