public void ToString_Should_Return_Name() { // Arrange TagViewModel model1 = new TagViewModel("tag1"); // Act + Assert Assert.That(model1.ToString(), Is.EqualTo("tag1")); }
public void Constructor_Should_Fill_Properties() { // Arrange + Act TagViewModel model = new TagViewModel("tag1"); // Assert Assert.That(model.Name, Is.EqualTo("tag1")); Assert.That(model.Count, Is.EqualTo(1)); }
public void Equals_Should_Use_Name_Property_For_Equality() { // Arrange TagViewModel model1 = new TagViewModel("tag1"); TagViewModel model2 = new TagViewModel("tag2"); // Act bool areEqual = model1.Equals(model2); // Assert Assert.That(areEqual, Is.False); }
public void equals_should_use_name_property_for_equality() { // Arrange TagViewModel model1 = new TagViewModel("tag1"); TagViewModel model2 = new TagViewModel("tag2"); // Act bool areEqual = model1.Equals(model2); // Assert Assert.That(areEqual, Is.False); }
public void Hashcode_Should_Change_For_Different_Objects_And_Not_Change_For_Lifetime_Of_Object() { // Arrange TagViewModel model1 = new TagViewModel("tag1"); TagViewModel model2 = new TagViewModel("tag2"); // Act int hashCode1 = model1.GetHashCode(); int hashCode2 = model2.GetHashCode(); int hashCode1a = model1.GetHashCode(); // Assert Assert.That(hashCode1, Is.Not.EqualTo(hashCode2)); Assert.That(hashCode1, Is.EqualTo(hashCode1a)); }
public void hashcode_should_change_for_different_objects_and_not_change_for_lifetime_of_object() { // Arrange TagViewModel model1 = new TagViewModel("tag1"); TagViewModel model2 = new TagViewModel("tag2"); // Act int hashCode1 = model1.GetHashCode(); int hashCode2 = model2.GetHashCode(); int hashCode1a = model1.GetHashCode(); // Assert Assert.That(hashCode1, Is.Not.EqualTo(hashCode2)); Assert.That(hashCode1, Is.EqualTo(hashCode1a)); }
/// <summary> /// Retrieves a list of all tags in the system. /// </summary> /// <returns>A <see cref="IEnumerable{TagViewModel}"/> for the tags.</returns> /// <exception cref="DatabaseException">An databaseerror occurred while getting the tags.</exception> public IEnumerable<TagViewModel> AllTags() { try { string cacheKey = "alltags"; List<TagViewModel> tags = _listCache.Get<TagViewModel>(cacheKey); if (tags == null) { IEnumerable<string> tagList = Repository.AllTags(); tags = new List<TagViewModel>(); foreach (string item in tagList) { foreach (string tagName in PageViewModel.ParseTags(item)) { if (!string.IsNullOrEmpty(tagName)) { TagViewModel tagModel = new TagViewModel(tagName); int index = tags.IndexOf(tagModel); if (index < 0) { tags.Add(tagModel); } else { tags[index].Count++; } } } } _listCache.Add<TagViewModel>(cacheKey, tags); } return tags; } catch (DatabaseException ex) { throw new DatabaseException(ex, "An error occurred while retrieving all tags from the database"); } }