Esempio n. 1
0
        public async Task Update_NotFound()
        {
            //Setup
            var id = Guid.NewGuid();

            var input = new ProfileUpdateViewModel()
            {
                FirstName   = "Upd",
                LastName    = "Upd",
                Gender      = "Upd",
                DateOfBirth = DateTimeOffset.Now.AddDays(1),
                City        = "Ct"
            };

            var serviceMock = new Mock <IProfileService>();

            serviceMock
            .Setup(x => x.UpdateAsync(id, input.FirstName, input.LastName, input.Gender, input.DateOfBirth, input.City, string.Empty))
            .ReturnsAsync(DomainResult.Error("NotFound"));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            //Act
            var response = await client.PutAsync($"profiles/{id}", input.AsJsonContent());

            //Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Esempio n. 2
0
        public DomainResult ProgressMatch(PlayerProgression playerProgression)
        {
            if (!_isStarted)
            {
                return(DomainResult.Error(new MatchDidNotStartYet()));
            }
            if (_isFinished)
            {
                return(DomainResult.Error(new MatchAllreadyFinished()));
            }

            var playerIsNotInHomeOrGuestTeam =
                !HomeTeamPlayers.Contains(playerProgression.PlayerId) &&
                !GuestTeamPlayers.Contains(playerProgression.PlayerId);

            if (playerIsNotInHomeOrGuestTeam)
            {
                return(DomainResult.Error(new PlayerWasNotPartOfTheTeamWhenStartingTheMatch(playerProgression.PlayerId)));
            }

            var playerProgressions = PlayerProgressions.Append(playerProgression);
            var gameResult         = CreateGameResult(playerProgressions);

            var matchResultUploaded = new MatchProgressed(MatchId, playerProgression, gameResult);

            return(DomainResult.Ok(matchResultUploaded));
        }
 public DomainResult ChangeId(string identity)
 {
     if (identity == null)
     {
         return(DomainResult.Error(new CanNotUSeNullId()));
     }
     return(DomainResult.Ok(new IdChanged(identity)));
 }
        public void CreatEnumErrorResult()
        {
            var domainResult = DomainResult.Error(MyTestEnum.WhateverError);

            var domainError = domainResult.DomainErrors.Single();

            Assert.AreEqual(domainError.ErrorType, MyTestEnum.WhateverError.ToString());
        }
        public void CreatTypelessErrorResult()
        {
            var domainDomainErrorKey = "errorKey";
            var domainResult         = DomainResult.Error(domainDomainErrorKey);

            var domainError = domainResult.DomainErrors.Single();

            Assert.AreEqual(domainError.ErrorType, domainDomainErrorKey);
        }
        public void CreatEnumErrorResultList()
        {
            var domainResult = DomainResult.Error(new List <Enum> {
                MyTestEnum.WhateverError, MyTestEnum.WhateverError
            });

            var domainError = domainResult.DomainErrors.First();

            Assert.AreEqual(domainError.ErrorType, MyTestEnum.WhateverError.ToString());
        }
        public void CreatTypelessErrorResultList()
        {
            var domainDomainErrorKey = "errorKey";
            var domainResult         = DomainResult.Error(new List <string> {
                domainDomainErrorKey, domainDomainErrorKey
            });

            var domainError = domainResult.DomainErrors.First();

            Assert.AreEqual(domainError.ErrorType, domainDomainErrorKey);
        }
Esempio n. 8
0
        public static DomainResult Create(
            TeamReadModel teamAtHome,
            TeamReadModel teamAsGuest)
        {
            if (teamAtHome.TeamId == teamAsGuest.TeamId)
            {
                return(DomainResult.Error(new TeamsCanNotBeTheSame(teamAtHome.TeamId, teamAsGuest.TeamId)));
            }

            return(Create(Guid.NewGuid(), teamAtHome, teamAsGuest));
        }
Esempio n. 9
0
 public DomainResult AddTeam(TeamReadModel teamId)
 {
     if (SeasonIsStarted)
     {
         return(DomainResult.Error(new SeasonAllreadyStarted()));
     }
     if (Teams.Any(t => t == teamId.TeamId))
     {
         return(DomainResult.Error(new CanNotAddTeamTwice(teamId.TeamId)));
     }
     return(DomainResult.Ok(new TeamAddedToSeason(SeasonId, teamId.TeamId)));
 }
Esempio n. 10
0
        public static DomainResult Create(
            Guid matchId,
            TeamReadModel teamAtHome,
            TeamReadModel teamAsGuest)
        {
            if (teamAtHome.TeamId == teamAsGuest.TeamId)
            {
                return(DomainResult.Error(new TeamsCanNotBeTheSame(teamAtHome.TeamId, teamAsGuest.TeamId)));
            }

            return(DomainResult.Ok(new MatchCreated(matchId, teamAtHome.TeamId, teamAsGuest.TeamId)));
        }
Esempio n. 11
0
        public DomainResult RegisterLevelUpSkillPointRoll(FreeSkillPoint freeSkillPoint)
        {
            if (ChoosableSkillPoints < 1)
            {
                return(DomainResult.Error(new PlayerIsNotLeveledUpAndHasNoFreeSkillPoints()));
            }

            var playerLevelUpPossibilitiesChosen = new PlayerLevelUpPossibilitiesChosen(PlayerId, freeSkillPoint);

            Apply(playerLevelUpPossibilitiesChosen);
            return(DomainResult.Ok(playerLevelUpPossibilitiesChosen));
        }
        public async Task <DomainResult> UpdateAsync(string commentId, string content)
        {
            try
            {
                await commentsApi.UpdateAsync(commentId, new UpdateCommentModel(content));
            }
            catch (ApiException)
            {
                return(DomainResult.Error("API error!"));
            }

            return(DomainResult.Success());
        }
        public async Task <DomainResult> ValidateAsync(Comment comment)
        {
            if (string.IsNullOrEmpty(comment.ReplyCommentId))
            {
                return(DomainResult.Success());
            }

            var parentComment = await commentsStorage.FindOneByIdAsync(comment.ReplyCommentId);

            return(parentComment == null
                ? DomainResult.Error("Parent comment not found")
                : DomainResult.Success());
        }
Esempio n. 14
0
        public async Task Create_ServiceError_BadRequest()
        {
            // Setup
            var input = new CreatePublicationModel
            {
                Content = "some content"
            };

            var serviceMock = new Mock <IPublicationService>();

            serviceMock
            .Setup(s => s.CreateAsync(It.IsAny <string>(), It.IsAny <UserInfo>()))
            .ReturnsAsync((DomainResult.Error("Some error"), default));
Esempio n. 15
0
        public DomainResult Finish()
        {
            if (!_isStarted)
            {
                return(DomainResult.Error(new MatchDidNotStartYet()));
            }
            if (_isFinished)
            {
                return(DomainResult.Error(new MatchAllreadyFinished()));
            }

            var gameResult = CreateGameResult(PlayerProgressions);

            var matchResultUploaded = new MatchFinished(MatchId, PlayerProgressions, gameResult);

            return(DomainResult.Ok(matchResultUploaded));
        }
Esempio n. 16
0
        public async Task <DomainResult> ValidateAsync(TContext context)
        {
            var errors = new List <DomainError>();

            foreach (var validator in validators)
            {
                var result = await validator.ValidateAsync(context);

                if (!result.Successed)
                {
                    errors.AddRange(result.Errors);
                }
            }

            return(errors.Any()
                ? DomainResult.Error(errors)
                : DomainResult.Success());
        }
Esempio n. 17
0
        public async Task Create_BadRequest()
        {
            // Setup
            const string publicationId = "publicationId";
            const string content       = "asd";
            const string authorId      = "3fa85f64-5717-4562-b3fc-2c963f66afa7";

            var author = new UserInfo(new Guid(authorId), "FName LName", null);

            var model = new CreateCommentModel()
            {
                Key            = publicationId,
                Content        = content,
                ReplyCommentId = null,
                AuthorId       = authorId
            };

            var serviceMock = new Mock <ICommentsService>();

            serviceMock
            .Setup(s => s.CreateAsync(publicationId, content, null, author))
            .ReturnsAsync((DomainResult.Error("somethig went wrong"), null));

            var userProvideMock = new Mock <IUserProvider>();

            userProvideMock
            .Setup(s => s.GetByIdAsync(model.AuthorId))
            .ReturnsAsync(author);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
                collection.AddScoped(_ => userProvideMock.Object);
            });

            // Act
            var response = await client.PostAsync("comments", model.AsJsonContent());

            // Asser
            Assert.AreEqual(response.StatusCode, HttpStatusCode.BadRequest);
        }
Esempio n. 18
0
        public async Task Create_BadRequest()
        {
            //Setup
            var id = Guid.NewGuid();

            var model = new WorkExperienceCreateViewModel
            {
                CompanyName = null,
                Description = null,
                StartWork   = DateTimeOffset.Now,
                FinishWork  = DateTimeOffset.Now.AddDays(1),
                ProfileId   = Guid.Empty
            };

            var serviceMock        = new Mock <IWorkExperienceService>();
            var profileServiceMock = new Mock <IProfileService>();

            serviceMock
            .Setup(x => x.CreateAsync(model.CompanyName, model.Description, model.StartWork, model.FinishWork,
                                      model.ProfileId))
            .ReturnsAsync((DomainResult.Error("Smt error"), default));
Esempio n. 19
0
        public DomainResult CommitDraft()
        {
            if (Players.Count() < 11)
            {
                return(DomainResult.Error(new TeamDoesNeedMorePlayersToFinish(Players.Count())));
            }

            var domainEvents = new List <IDomainEvent>();

            domainEvents.Add(new TeamCreated(TeamId, RaceId, TeamName, TrainerName, AllowedPlayers, TeamMoney));
            domainEvents.AddRange(Players.Select(player => new PlayerBought(
                                                     TeamId,
                                                     player.PlayerTypeId,
                                                     player.PlayerPositionNumber,
                                                     player.PlayerId,
                                                     TeamMoney)));

            Apply(domainEvents);

            return(DomainResult.Ok(domainEvents));
        }
Esempio n. 20
0
        public async Task <DomainResult> UpdateAsync(User user)
        {
            var profile = await profilesApi.GetByIdAsync(user.Id);

            var updateCommand = new ProfileUpdateViewModel(
                profile.FirstName,
                profile.LastName,
                user.Gender,
                user.DateOfBirth,
                profile.City);

            try
            {
                await profilesApi.UpdateAsync(user.Id, updateCommand);

                return(DomainResult.Success());
            }
            catch (Profiles.Client.ApiException ex) when(ex.ErrorCode == (int)HttpStatusCode.BadRequest)
            {
                return(DomainResult.Error("ERROR!!!!"));
            }
        }
Esempio n. 21
0
        public DomainResult StartSeason()
        {
            if (Teams.Count() < 2)
            {
                return(DomainResult.Error(new SeasonMustHaveAtLeast2Teams(Teams.Count())));
            }
            if (TeamCountIsUneven())
            {
                return(DomainResult.Error(new CanNotStartSeasonWithUnevenTeamCount(Teams.Count())));
            }
            if (SeasonIsStarted)
            {
                return(DomainResult.Error(new CanNotStartSeasonASecondTime()));
            }

            var matchPairingService = new MatchPairingService();
            var gameDays            = matchPairingService.ComputePairings(Teams).ToList();

            var seasonStarted = new SeasonStarted(SeasonId, gameDays, DateTimeOffset.UtcNow);

            return(DomainResult.Ok(seasonStarted));
        }
 private DomainResult Validate(string content)
 {
     return(forbiddenWords.Any(content.Contains)
         ? DomainResult.Error("Content contains forbidden words")
         : DomainResult.Success());
 }
Esempio n. 23
0
 private DomainResult Validate(string content)
 {
     return(content.Length < minLength
         ? DomainResult.Error($"Content length is less than {minLength} characters")
         : DomainResult.Success());
 }
 private DomainResult Validate(DateTimeOffset createdOn)
 {
     return(createdOn.Add(timeLimit) < DateTimeOffset.UtcNow
         ? DomainResult.Error($"Entity cannot update after {timeLimit.TotalMinutes} minutes after it was created")
         : DomainResult.Success());
 }