public void Should_fire_serializer_with_correct_artist_if_file_does_not_exist()
 {
     _fileWrapper.Stub(x => x.FileExists("")).IgnoreArguments().Return(false);
     var artistWriter = new ArtistWriter(_fileWrapper, _serializer);
     var artist = new Artist(){Id=1, Genre="Rock",Name="Test"};
     artistWriter.CreateFile(artist);
     _serializer.AssertWasCalled(x => x.Serialize(artist));
 }
Exemple #2
0
        /// <summary>
        /// This method deletes a 'Artist' object.
        /// </summary>
        /// <param name='List<PolymorphicObject>'>The 'Artist' to delete.
        /// <returns>A PolymorphicObject object with a Boolean value.
        internal PolymorphicObject DeleteArtist(List <PolymorphicObject> parameters, DataConnector dataConnector)
        {
            // Initial Value
            PolymorphicObject returnObject = new PolymorphicObject();

            // If the data connection is connected
            if ((dataConnector != null) && (dataConnector.Connected == true))
            {
                // Create Delete StoredProcedure
                DeleteArtistStoredProcedure deleteArtistProc = null;

                // verify the first parameters is a(n) 'Artist'.
                if (parameters[0].ObjectValue as Artist != null)
                {
                    // Create Artist
                    Artist artist = (Artist)parameters[0].ObjectValue;

                    // verify artist exists
                    if (artist != null)
                    {
                        // Now create deleteArtistProc from ArtistWriter
                        // The DataWriter converts the 'Artist'
                        // to the SqlParameter[] array needed to delete a 'Artist'.
                        deleteArtistProc = ArtistWriter.CreateDeleteArtistStoredProcedure(artist);
                    }
                }

                // Verify deleteArtistProc exists
                if (deleteArtistProc != null)
                {
                    // Execute Delete Stored Procedure
                    bool deleted = this.DataManager.ArtistManager.DeleteArtist(deleteArtistProc, dataConnector);

                    // Create returnObject.Boolean
                    returnObject.Boolean = new NullableBoolean();

                    // If delete was successful
                    if (deleted)
                    {
                        // Set returnObject.Boolean.Value to true
                        returnObject.Boolean.Value = NullableBooleanEnum.True;
                    }
                    else
                    {
                        // Set returnObject.Boolean.Value to false
                        returnObject.Boolean.Value = NullableBooleanEnum.False;
                    }
                }
            }
            else
            {
                // Raise Error Data Connection Not Available
                throw new Exception("The database connection is not available.");
            }

            // return value
            return(returnObject);
        }
        public void Should_fire_save_with_correct_xml_if_file_does_not_exist()
        {
            var xPathNavigable = MockRepository.GenerateStub<XmlDocument>();
            _fileWrapper.Stub(x => x.FileExists("")).IgnoreArguments().Return(false);
            _serializer.Stub(x => x.Serialize(null)).IgnoreArguments().Return(xPathNavigable);

            var artistWriter = new ArtistWriter(_fileWrapper, _serializer);
            var artist = new Artist() { Id = 1, Genre = "Rock", Name = "Test" };
            artistWriter.CreateFile(artist);
            _fileWrapper.AssertWasCalled(x => x.WriteFile(Arg<string>.Is.Anything, Arg<string>.Is.Anything));
        }
Exemple #4
0
        /// <summary>
        /// This method finds a 'Artist' object.
        /// </summary>
        /// <param name='List<PolymorphicObject>'>The 'Artist' to delete.
        /// <returns>A PolymorphicObject object with a Boolean value.
        internal PolymorphicObject FindArtist(List <PolymorphicObject> parameters, DataConnector dataConnector)
        {
            // Initial Value
            PolymorphicObject returnObject = new PolymorphicObject();

            // locals
            Artist artist = null;

            // If the data connection is connected
            if ((dataConnector != null) && (dataConnector.Connected == true))
            {
                // Create Find StoredProcedure
                FindArtistStoredProcedure findArtistProc = null;

                // verify the first parameters is a 'Artist'.
                if (parameters[0].ObjectValue as Artist != null)
                {
                    // Get ArtistParameter
                    Artist paramArtist = (Artist)parameters[0].ObjectValue;

                    // verify paramArtist exists
                    if (paramArtist != null)
                    {
                        // Now create findArtistProc from ArtistWriter
                        // The DataWriter converts the 'Artist'
                        // to the SqlParameter[] array needed to find a 'Artist'.
                        findArtistProc = ArtistWriter.CreateFindArtistStoredProcedure(paramArtist);
                    }

                    // Verify findArtistProc exists
                    if (findArtistProc != null)
                    {
                        // Execute Find Stored Procedure
                        artist = this.DataManager.ArtistManager.FindArtist(findArtistProc, dataConnector);

                        // if dataObject exists
                        if (artist != null)
                        {
                            // set returnObject.ObjectValue
                            returnObject.ObjectValue = artist;
                        }
                    }
                }
                else
                {
                    // Raise Error Data Connection Not Available
                    throw new Exception("The database connection is not available.");
                }
            }

            // return value
            return(returnObject);
        }
Exemple #5
0
        /// <summary>
        /// This method fetches all 'Artist' objects.
        /// </summary>
        /// <param name='List<PolymorphicObject>'>The 'Artist' to delete.
        /// <returns>A PolymorphicObject object with all  'Artists' objects.
        internal PolymorphicObject FetchAll(List <PolymorphicObject> parameters, DataConnector dataConnector)
        {
            // Initial Value
            PolymorphicObject returnObject = new PolymorphicObject();

            // locals
            List <Artist> artistListCollection = null;

            // Create FetchAll StoredProcedure
            FetchAllArtistsStoredProcedure fetchAllProc = null;

            // If the data connection is connected
            if ((dataConnector != null) && (dataConnector.Connected == true))
            {
                // Get ArtistParameter
                // Declare Parameter
                Artist paramArtist = null;

                // verify the first parameters is a(n) 'Artist'.
                if (parameters[0].ObjectValue as Artist != null)
                {
                    // Get ArtistParameter
                    paramArtist = (Artist)parameters[0].ObjectValue;
                }

                // Now create FetchAllArtistsProc from ArtistWriter
                fetchAllProc = ArtistWriter.CreateFetchAllArtistsStoredProcedure(paramArtist);
            }

            // Verify fetchAllProc exists
            if (fetchAllProc != null)
            {
                // Execute FetchAll Stored Procedure
                artistListCollection = this.DataManager.ArtistManager.FetchAllArtists(fetchAllProc, dataConnector);

                // if dataObjectCollection exists
                if (artistListCollection != null)
                {
                    // set returnObject.ObjectValue
                    returnObject.ObjectValue = artistListCollection;
                }
            }
            else
            {
                // Raise Error Data Connection Not Available
                throw new Exception("The database connection is not available.");
            }

            // return value
            return(returnObject);
        }
 public void Should_throw_exception_if_file_already_exists()
 {
     _fileWrapper.Stub(x => x.FileExists("")).IgnoreArguments().Return(true);
     var artistWriter = new ArtistWriter(_fileWrapper, _serializer);
     Assert.Throws<ResourceExistsException>(() => artistWriter.CreateFile(new Artist()));
 }
 public void Should_create_folder_if_does_not_exist()
 {
     var artistReader = new ArtistWriter(_fileWrapper, _serializer);
     artistReader.CreateFile(new Artist());
     _fileWrapper.AssertWasCalled(x => x.CreateDirectory("C:/artist"));
 }