コード例 #1
0
        public void AddCoach_GetCoachList_IsFiguringOnList(string firstName, string surname, string email, string phoneNumber)
        {
            var trackingLogsService = new Mock <ITrackingLogsService>();

            trackingLogsService.Setup(service => service.SendEvent(
                                          It.IsAny <TrackingLogEvent>())).Returns(ServiceResponse.Success());

            var sut = new CoachService(new FakeCoachRepository(), trackingLogsService.Object);

            sut.EnsureInitialized("DummyURL", "0001");

            var coach = new Coach()
            {
                FirstName   = firstName,
                Surname     = surname,
                Email       = email,
                PhoneNumber = phoneNumber
            };

            var addedCoach        = sut.AddCoach(coach).ResponseDTO;
            var obtainedCoachList = sut.GetCoachList().ResponseDTO;
            var obtainedCoach     = obtainedCoachList.FirstOrDefault(c => c.Id == addedCoach.Id);

            obtainedCoach.Should().NotBeNull().And.Match <Coach>(c =>
                                                                 c.FirstName == firstName && c.Surname == surname &&
                                                                 c.Email == email && c.PhoneNumber == phoneNumber);
        }
コード例 #2
0
        public void AddCoach_DeleteCoach_GetCoach_IsNotFound(string firstName, string surname, string email, string phoneNumber)
        {
            var trackingLogsService = new Mock <ITrackingLogsService>();

            trackingLogsService.Setup(service => service.SendEvent(
                                          It.IsAny <TrackingLogEvent>())).Returns(ServiceResponse.Success());

            var sut = new CoachService(new FakeCoachRepository(), trackingLogsService.Object);

            sut.EnsureInitialized("DummyURL", "0001");

            var coach = new Coach()
            {
                FirstName   = firstName,
                Surname     = surname,
                Email       = email,
                PhoneNumber = phoneNumber
            };

            var addedCoach = sut.AddCoach(coach).ResponseDTO;

            sut.DeleteCoach(addedCoach.Id);
            var getCoach = sut.GetCoach(addedCoach.Id);

            getCoach.Should().Match <ServiceResponse>(response => !response.IsSuccess && response.ErrorDetails.Code == 404);
        }
コード例 #3
0
        public void AddCoach_DeleteCoach_GetCoachList_IsNotFiguringOnList(string firstName, string surname, string email, string phoneNumber)
        {
            var trackingLogsService = new Mock <ITrackingLogsService>();

            trackingLogsService.Setup(service => service.SendEvent(
                                          It.IsAny <TrackingLogEvent>())).Returns(ServiceResponse.Success());

            var sut = new CoachService(new FakeCoachRepository(), trackingLogsService.Object);

            sut.EnsureInitialized("DummyURL", "0001");

            var coach = new Coach()
            {
                FirstName   = firstName,
                Surname     = surname,
                Email       = email,
                PhoneNumber = phoneNumber
            };

            var addedCoach = sut.AddCoach(coach).ResponseDTO;

            sut.DeleteCoach(addedCoach.Id);
            var getCoachList = sut.GetCoachList().ResponseDTO;

            //getCoachList.Should().Match<List<Coach>>(response => response.Count==0);
            getCoachList.Should().NotContain(addedCoach);
        }
コード例 #4
0
        public void AddCoach_GetLatestLogs_IsEventSaved()
        {
            //mocking repos
            var fakeCoachRep = new FakeCoachRepository();
            var fakeLogRep   = new FakeTrackingLogEventRepository();

            //systems under test ( tracking side)
            var trackingService    = new TrackingService(fakeLogRep);
            var trackingController = new TrackingController(trackingService);

            _fixture.InitTrackingController(trackingController);

            //system under test ( main app side)
            var trackingLogsService = new TrackingLogsService(_fixture.Configuration, _fixture.FakeHttpService);
            var coachService        = new CoachService(fakeCoachRep, trackingLogsService);

            //testing and assertions
            var addCoachResponse = coachService.AddCoach(new Coach());

            addCoachResponse.Should().Match <ServiceResponse <Coach> >(response => response.IsSuccess);
            var logListResponse = trackingLogsService.GetLatestLogs();

            logListResponse.Should().Match <ServiceResponse <List <TrackingLogEvent> > >(response => response.IsSuccess);

            logListResponse.ResponseDTO.Should()
            .Contain(eventLog => eventLog.EventTypeId == TrackingLogEventType.CoachAdded);
        }
コード例 #5
0
        public void AddCoach_IsDataMatching(string firstName, string surname, string email, string phoneNumber)
        {
            var coachRepositoryMock = new Mock <ICoachRepository>();
            var coach = new Coach();

            coachRepositoryMock.Setup(repository => repository.InsertCoach(coach))
            .Returns(new Coach()
            {
                FirstName   = firstName,
                Surname     = surname,
                Email       = email,
                PhoneNumber = phoneNumber
            });


            var trackingLogsService = new Mock <ITrackingLogsService>();

            trackingLogsService.Setup(service => service.SendEvent(
                                          It.IsAny <TrackingLogEvent>())).Returns(ServiceResponse.Success());

            var sut = new CoachService(coachRepositoryMock.Object, trackingLogsService.Object);

            sut.EnsureInitialized("DummyURL", "0001");

            sut.AddCoach(coach).Should().Match <ServiceResponse <Coach> >(response =>
                                                                          response.ResponseDTO.FirstName == firstName && response.ResponseDTO.Surname == surname &&
                                                                          response.ResponseDTO.Email == email && response.ResponseDTO.PhoneNumber == phoneNumber
                                                                          );
        }
コード例 #6
0
        public void AddCoach_IsNewIdReceived()
        {
            var coachRepositoryMock = new FakeCoachRepository();

            var trackingLogsService = new Mock <ITrackingLogsService>();

            trackingLogsService.Setup(service => service.SendEvent(
                                          It.IsAny <TrackingLogEvent>())).Returns(ServiceResponse.Success());

            var sut = new CoachService(coachRepositoryMock, trackingLogsService.Object);

            sut.EnsureInitialized("DummyURL", "0001");

            var coachResponse  = sut.AddCoach(new Coach());
            var coach2Response = sut.AddCoach(new Coach());

            coach2Response.Should().Match <ServiceResponse <Coach> >(response =>
                                                                     response.ResponseDTO.Id != 0 && coachResponse.ResponseDTO.Id != 0 &&
                                                                     response.ResponseDTO.Id != coachResponse.ResponseDTO.Id);
        }
コード例 #7
0
        public void AddCoach_Saves_Coach()
        {
            Coach coach = new Coach()
            {
                Age  = 20,
                Name = "Name"
            };

            coachService.AddCoach(coach);

            coachSet.Verify(m => m.Add(It.IsAny <Coach>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
コード例 #8
0
        public void AddCoach_IsSuccess()
        {
            var coachRepositoryMock = new Mock <ICoachRepository>();
            var coach = new Coach();

            coachRepositoryMock.Setup(repository => repository.InsertCoach(coach)).Returns(coach);
            var trackingLogsService = new Mock <ITrackingLogsService>();

            trackingLogsService.Setup(service => service.SendEvent(
                                          It.IsAny <TrackingLogEvent>())).Returns(ServiceResponse.Success());

            var sut = new CoachService(coachRepositoryMock.Object, trackingLogsService.Object);

            sut.EnsureInitialized("DummyURL", "0001");

            sut.AddCoach(coach).Should().Match <ServiceResponse <Coach> >(response => response.IsSuccess);
        }
コード例 #9
0
        public void AddCoach_UpdateCoach_IsSuccess(string firstName, string surname, string email, string phoneNumber)
        {
            var trackingLogsService = new Mock <ITrackingLogsService>();

            trackingLogsService.Setup(service => service.SendEvent(
                                          It.IsAny <TrackingLogEvent>())).Returns(ServiceResponse.Success());

            var sut = new CoachService(new FakeCoachRepository(), trackingLogsService.Object);

            sut.EnsureInitialized("DummyURL", "0001");

            var coach = new Coach()
            {
                FirstName   = firstName,
                Surname     = surname,
                Email       = email,
                PhoneNumber = phoneNumber
            };

            var addedCoach     = sut.AddCoach(coach).ResponseDTO;
            var updateResponse = sut.UpdateCoach(addedCoach);

            updateResponse.Should().Match <ServiceResponse <Coach> >(response => response.IsSuccess);
        }