Ejemplo n.º 1
0
        public void When_About_is_called_GetBand_on_IBandProcess_is_called_with_the_correct_parameter_and_the_result_is_mapped_with_BandMapper()
        {
            var entity = BandCreator.CreateSingle();

            BandProcess
            .Expect(process =>
                    process.GetBand())
            .Return(entity)
            .Repeat.Once();
            BandProcess.Replay();

            var detailModel = CreateAboutModel();

            BandMapper
            .Expect(mapper =>
                    mapper.MapToAboutModel(entity))
            .Return(detailModel)
            .Repeat.Once();
            BandMapper.Replay();

            var result = Controller.About().Result as ViewResult;

            Assert.IsNotNull(result);

            BandProcess.VerifyAllExpectations();
            BandMapper.VerifyAllExpectations();
        }
Ejemplo n.º 2
0
        public void When_UpdateModel_is_mapped_to_an_Entity_and_the_Info_is_null_then_all_fields_are_mapped_correctly_and_Info_in_the_result_is_null()
        {
            var entity = BandCreator.CreateSingle();

            BandProcess
            .Expect(process =>
                    process.GetBand())
            .Return(entity)
            .Repeat.Once();
            BandProcess.Replay();

            var updateModel = new AboutUpdateModel
            {
                DateFounded = DateTime.Now.AddMonths(-4).Date,
                Info        = null,
            };

            var result = Mapper.Map(updateModel);

            Assert.AreEqual(entity.Id, result.Id, "Id not correct");
            Assert.AreEqual(updateModel.DateFounded.ToUniversalTime(), result.Founded, "Date founded not correct");
            Assert.AreEqual(null, result.Description, "Description not correct");

            BandProcess.VerifyAllExpectations();
        }
        public void When_Band_is_mapped_to_an_UpdateModel_then_all_corresponding_fields_are_mapped()
        {
            var entity = BandCreator.CreateSingle();

            var result = Mapper.MapToAboutUpdateModel(entity);

            Assert.AreEqual(entity.Founded.ToLocalTime(), result.DateFounded);
            Assert.AreEqual(entity.Description, result.Info);
        }
Ejemplo n.º 4
0
        public void When_GetBand_is_called_with_an_Id_and_there_is_no_Band_in_the_collection_with_that_Id_then_an_InvalidOperationException_is_thrown()
        {
            var bands  = BandCreator.CreateCollection();
            var bandId = Guid.NewGuid();

            AppCatalog
            .Expect(catalog => catalog.Bands)
            .Return(bands)
            .Repeat.Once();
            AppCatalog.Replay();

            Repository.GetBand(bandId);
        }
Ejemplo n.º 5
0
        public void When_Band_is_mapped_to_a_DetailsModel_then_no_data_is_retrieved_from_process_classes()
        {
            BandProcess
            .Expect(process =>
                    process.GetBand())
            .Repeat.Never();
            BandProcess.Replay();

            var entity = BandCreator.CreateSingle();

            var result = Mapper.MapToAboutModel(entity);

            Assert.AreEqual(entity.Founded.ToLocalTime(), result.DateFounded);
            Assert.AreEqual(entity.Description, result.Info);
        }
Ejemplo n.º 6
0
        public void When_AddBand_is_called_with_a_valid_Band_then_the_Band_is_added_to_the_collection()
        {
            var band = BandCreator.CreateSingle();

            AppCatalog
            .Expect(catalog => catalog.Add(band))
            .Return(band)
            .Repeat.Once();
            AppCatalog.Replay();

            band = Repository.AddBand(band);

            Assert.IsNotNull(band);

            AppCatalog.VerifyAllExpectations();
        }
Ejemplo n.º 7
0
        public void When_EnsureBandExists_is_called_and_more_than_one_Band_exists_then_an_Exception_is_thrown()
        {
            var bands = BandCreator.CreateCollection();

            AppRepository
            .Expect(repository =>
                    repository.GetAllBands())
            .Return(bands)
            .Repeat.Once();
            AppRepository
            .Expect(repository =>
                    repository.AddBand(Arg <Band> .Is.NotNull))
            .Repeat.Never();
            AppRepository.Replay();

            Process.EnsureBandExists();
        }
Ejemplo n.º 8
0
        public void When_UpdateBand_is_called_with_a_valid_Band_then_the_Band_is_updated_in_the_collection()
        {
            var entity = BandCreator.CreateSingle();

            AppCatalog
            .Expect(catalog => catalog.Update(entity))
            .Return(entity)
            .Repeat.Once();
            AppCatalog.Replay();

            var result = Repository.UpdateBand(entity);

            Assert.IsNotNull(result);
            Assert.AreEqual(entity.Id, result.Id);

            AppCatalog.VerifyAllExpectations();
        }
Ejemplo n.º 9
0
        public void When_GetBand_is_called_without_an_Id_then_the_current_Band_is_retrieved_from_the_collection()
        {
            var band = BandCreator.CreateSingle();

            AppCatalog
            .Expect(catalog => catalog.CurrentBand)
            .Return(band)
            .Repeat.Once();
            AppCatalog.Replay();

            var result = Repository.GetBand();

            Assert.IsNotNull(result);
            Assert.AreEqual(band, result);

            AppCatalog.VerifyAllExpectations();
        }
Ejemplo n.º 10
0
        public void When_Encrypt_is_called_multiple_times_then_GetBand_on_the_AppRepository_is_called_once()
        {
            const string value = "This is a value that will be encrypted";
            var          band  = BandCreator.CreateSingle();

            AppRepository
            .Expect(repository =>
                    repository.GetBand())
            .Return(band)
            .Repeat.Once();
            AppRepository.Replay();

            Process.Encrypt(value);
            Process.Encrypt(value);

            AppRepository.VerifyAllExpectations();
        }
Ejemplo n.º 11
0
        public void When_UpdateBand_is_called_then_UpdateBand_on_the_AppRepository_is_called()
        {
            var entity = BandCreator.CreateSingle();

            AppRepository
            .Expect(repository =>
                    repository.UpdateBand(entity))
            .Return(entity)
            .Repeat.Once();
            AppRepository.Replay();

            var result = Process.UpdateBand(entity);

            Assert.AreEqual(entity, result);

            AppRepository.VerifyAllExpectations();
        }
Ejemplo n.º 12
0
        public void When_Band_is_mapped_to_a_DetailsModel_and_the_Description_is_null_then_the_Info_is_stringEmpty()
        {
            BandProcess
            .Expect(process =>
                    process.GetBand())
            .Repeat.Never();
            BandProcess.Replay();

            var entity = BandCreator.CreateSingle();

            entity.Description = null;

            var result = Mapper.MapToAboutModel(entity);

            Assert.AreEqual(entity.Founded.ToLocalTime(), result.DateFounded);
            Assert.AreEqual(string.Empty, result.Info);
        }
Ejemplo n.º 13
0
        public void When_GetBand_is_called_with_an_Id_then_the_Band_with_the_corresponding_Id_is_retrieved_from_the_collection()
        {
            var bands  = BandCreator.CreateCollection();
            var bandId = bands.ElementAt(2).Id;

            AppCatalog
            .Expect(catalog => catalog.Bands)
            .Return(bands)
            .Repeat.Once();
            AppCatalog.Replay();

            var band = Repository.GetBand(bandId);

            Assert.IsNotNull(band);
            Assert.AreEqual(bandId, band.Id);

            AppCatalog.VerifyAllExpectations();
        }
Ejemplo n.º 14
0
        public void When_GetAllBands_is_called_then_all_Bands_are_retrieved_from_the_collection()
        {
            var bands = BandCreator.CreateCollection();

            AppCatalog
            .Expect(catalog => catalog.Bands)
            .Return(bands)
            .Repeat.Once();
            AppCatalog.Replay();

            var result = Repository.GetAllBands();

            Assert.IsNotNull(result);
            Assert.AreEqual(bands.Count(), result.Count());
            Assert.AreEqual(bands, result);

            AppCatalog.VerifyAllExpectations();
        }
Ejemplo n.º 15
0
        public void When_Decrypt_is_called_with_an_encrypted_value_then_the_result_is_the_original_value()
        {
            const string value = "This is a value that will be encrypted";
            var          band  = BandCreator.CreateSingle();

            AppRepository
            .Expect(repository =>
                    repository.GetBand())
            .Return(band)
            .Repeat.Once();
            AppRepository.Replay();

            var encryptedValue = Process.Encrypt(value);
            var decryptedValue = Process.Decrypt(encryptedValue);

            Assert.AreEqual(value, decryptedValue);

            AppRepository.VerifyAllExpectations();
        }
Ejemplo n.º 16
0
        public void When_Encrypt_is_called_multiple_times_then_the_result_differs_each_time()
        {
            const string value = "This is a value that will be encrypted";
            var          band  = BandCreator.CreateSingle();

            AppRepository
            .Expect(repository =>
                    repository.GetBand())
            .Return(band)
            .Repeat.Once();
            AppRepository.Replay();

            var result1 = Process.Encrypt(value);
            var result2 = Process.Encrypt(value);

            Assert.IsFalse(string.IsNullOrEmpty(result1));
            Assert.IsFalse(string.IsNullOrEmpty(result2));
            Assert.AreNotEqual(result1, result2);

            AppRepository.VerifyAllExpectations();
        }
Ejemplo n.º 17
0
        public void When_EnsureBandExists_is_called_and_one_Band_exists_then_only_GetAllBands_on_the_AppRepository_is_called()
        {
            var band = BandCreator.CreateSingle();

            AppRepository
            .Expect(repository =>
                    repository.GetAllBands())
            .Return(new List <Band> {
                band
            })
            .Repeat.Once();
            AppRepository
            .Expect(repository =>
                    repository.AddBand(Arg <Band> .Is.NotNull))
            .Repeat.Never();
            AppRepository.Replay();

            var result = Process.EnsureBandExists();

            Assert.AreEqual(band.Id, result.Id);

            AppRepository.VerifyAllExpectations();
        }
 public BandLidController()
 {
     bands = BandCreator.StartUp();
 }
Ejemplo n.º 19
0
        public void When_CreatUser_is_called_then_the_User_is_created_and_registered_under_the_Band_that_is_provided_by_the_BandProcess()
        {
            var          band              = BandCreator.CreateSingle();
            var          user              = UserCreator.CreateSingle();
            var          login             = user.Login;
            const string encryptedPassword = "******";

            BandProcess
            .Expect(process => process.EnsureBandExists())
            .Return(band)
            .Repeat.Once();
            BandProcess.Replay();

            CryptographyProcess
            .Expect(process => process.Encrypt(login.Password))
            .Return(encryptedPassword)
            .Repeat.Once();
            CryptographyProcess.Replay();

            UserProcess
            .Expect(process => process.GetUserByLoginName(Arg <string> .Is.Anything))
            .Return(null)
            .Repeat.Once();
            UserProcess
            .Expect(process => process.GetUserByEmailAddress(Arg <string> .Is.Anything))
            .Return(null)
            .Repeat.Once();
            UserProcess
            .Expect(process =>
                    process.AddUser(Arg <User> .Matches(u =>
                                                        u.BandId == band.Id &&
                                                        u.Login.Password == encryptedPassword &&
                                                        u.Login.IsOnline &&
                                                        u.Login.LastLoginDate > DateTime.UtcNow.AddSeconds(-2) &&
                                                        u.Login.LastActivityDate > DateTime.UtcNow.AddSeconds(-2) &&
                                                        u.Login.LastPasswordChangedDate >
                                                        DateTime.UtcNow.AddSeconds(-2))))
            .Return(user)
            .Repeat.Once();
            UserProcess.Replay();

            var membershipUser = CreateMembershipUser(user);

            UserMapper
            .Expect(mapper => mapper.Map(user))
            .Return(membershipUser)
            .Repeat.Once();
            UserMapper.Replay();

            MembershipCreateStatus createStatus;
            var result = CustomMembershipProvider.CreateUser(
                login.LoginName,
                login.Password,
                login.EmailAddress,
                string.Empty,
                string.Empty,
                login.IsApproved,
                login.Id,
                out createStatus);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ProviderUserKey);
            Assert.AreEqual(user.Login.LoginName, result.UserName);
            Assert.AreEqual(MembershipCreateStatus.Success, createStatus);

            BandProcess.VerifyAllExpectations();
            CryptographyProcess.VerifyAllExpectations();
            UserProcess.VerifyAllExpectations();
            UserMapper.VerifyAllExpectations();
        }