public void Add_WithTheSameLocation_ReturnUnsuccessful( FriendService sut, Friend newFriend) { var myFriendsCollection = Builder <Friend> .CreateListOfSize(10).All() .TheFirst(1) .With(x => x.Name = "Sergio") .With(x => x.Location = new Location { Latitude = 10, Longitude = 10 }) .Build() .ToList(); sut.InMemoryCacheService.Remove(CacheKey); sut.InMemoryCacheService.Insert(CacheKey, myFriendsCollection); newFriend.Location.Latitude = 10; newFriend.Location.Longitude = 10; var result = sut.Add(newFriend); Assert.False(result.Succeeded); Assert.True(result.Reason == ServiceResultFailReason.BusinessValidation); Assert.Contains("Já existe um amigo nessa mesma localização.", result.Errors); }
public ActionResult Add(Friend entity) { entity.DelFlag = true; entity.RegTime = DateTime.Now; entity.Status = 1; FriendService.Add(entity); return(Json(new { status = 1, msg = "成功" })); }
public void Add_WithLocationIsNull_ReturnUnsuccessful(FriendService sut, Friend newFriend) { newFriend.Location = null; var result = sut.Add(newFriend); Assert.False(result.Succeeded); Assert.True(result.Reason == ServiceResultFailReason.BusinessValidation); Assert.Contains("Infome a localização do seu amigo.", result.Errors); }
public void Add_WithNameIsEmpty_ReturnUnsuccessful(FriendService sut, Friend newFriend) { newFriend.Name = string.Empty; var result = sut.Add(newFriend); Assert.False(result.Succeeded); Assert.True(result.Reason == ServiceResultFailReason.BusinessValidation); Assert.Contains("Informe o nome do seu amigo", result.Errors); }
public ActionResult AddFriend(int FriendID) { Friend entity = new Friend(); entity.FriendID = FriendID; entity.UserInfoID = LoginUser.ID; entity.DelFlag = true; entity.RegTime = DateTime.Now; entity.Status = 1; var user = FriendService.GetEntity(u => u.FriendID == FriendID && u.UserInfoID == LoginUser.ID).FirstOrDefault(); if (user == null) { FriendService.Add(entity); return(Json(new { status = 1, msg = "成功" })); } return(Json(new { status = 0, msg = "你们已经是好友了!!" })); }